home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d149 / dx-voicesorter.lha / DX-VoiceSorter / voicesorter.c < prev    next >
C/C++ Source or Header  |  1987-06-15  |  16KB  |  578 lines

  1. /***************************************************************************
  2.  *DX7 Fileshifter                                            David Bouckley*
  3.  *Copyright David Bouckley (1988)                                          *
  4.  *                                                                         *
  5.  *   This program allows for sorting of individual voices from Yamaha DX7  *
  6.  * voice files saved using Jack Deckard's Voicefiler program found on      *
  7.  * Fish Disks 38 and 82. It may be freely used so long as no commercial    *
  8.  * gain is made from either the program or it's code.                      *
  9.  ***************************************************************************/
  10.  
  11. #include <exec/types.h>                 /*Files to include*/
  12. #include <intuition/intuition.h>
  13. #include <libraries/dos.h>
  14. #include <exec/exec.h>
  15. #include <intuition/intuitionbase.h>
  16.  
  17. struct IntuitionBase *IntuitionBase;    /*Structures Used*/
  18. struct GfxBase *GfxBase;             
  19. struct Window *Window; 
  20. struct Message *GetMsg();
  21. struct Screen *Screen;
  22. struct Menu menu[1];
  23. struct MenuItem menuitem[4];
  24. struct IntuiText menutext[4];
  25. struct IntuiMessage *NewMessage;
  26. struct Gadget gadget[65];
  27.  
  28. #define INTUITION_REV 1L                /*Define Manx Version*/
  29. #define GRAPHICS_REV 1L            
  30.  
  31. UBYTE infile[4096];         /*File Storage For Input*/
  32. UBYTE buffer[4096];         /*File Storage For Buffer*/
  33. UBYTE buff[128];            /*Individual Voice Buffer*/
  34. static char name[26];
  35. char *inname[32];
  36.  
  37. /* Initialize the NewWindow structure for the call to OpenWindow() */
  38. struct NewWindow NewWindow =
  39. {
  40.        150,10,480,185,0,1,
  41.        REFRESHWINDOW | MOUSEBUTTONS | MOUSEMOVE | GADGETDOWN | GADGETUP |    
  42.        CLOSEWINDOW | MENUPICK | VANILLAKEY,
  43.        WINDOWSIZING | WINDOWCLOSE | REPORTMOUSE | 
  44.        SMART_REFRESH | ACTIVATE | WINDOWDRAG | WINDOWDEPTH,
  45.        &gadget[0], NULL,
  46.        "DX7 VoiceSorter",
  47.        NULL, NULL,
  48.        0,0,240,100,
  49.        WBENCHSCREEN,
  50. };
  51.  
  52. /* function to get file name*/
  53. VOID filename(across)
  54. int across;
  55. {
  56.    ULONG   class, code, keepgoing = 1, i = 0;
  57.    LONG   x = across;
  58.    Move(Window->RPort,across,17);
  59.    Text(Window->RPort,"                 ",17);
  60.    Move(Window->RPort,across,17);      
  61.    Text(Window->RPort,"Filename:" ,9);     
  62.    Move(Window->RPort,across,25);
  63.    Text(Window->RPort,"                           ",27);
  64.    Move(Window->RPort,across,25);
  65.    while(keepgoing)
  66.    {
  67.       Wait( 1L << Window -> UserPort -> mp_SigBit);
  68.       while(NewMessage=(struct IntuiMessage *)GetMsg(Window->UserPort))
  69.       {
  70.          class = NewMessage->Class;
  71.          code = NewMessage->Code;
  72.          ReplyMsg(NewMessage);
  73.          if(class = VANILLAKEY)
  74.          {
  75.             switch(code)
  76.             {
  77.                case (13):   /* return   */
  78.                {
  79.                   name[i]=0;
  80.                   keepgoing = 0;
  81.                   break;
  82.                }
  83.                case (27):   /* ESC   */
  84.                {
  85.                   name[0]=0;
  86.                   keepgoing = 0;
  87.                   break;
  88.                }
  89.                case (8):
  90.                   if (i > 0) /* backspace   */
  91.                   {
  92.                      i--;
  93.                      name[i] = 0;
  94.                      x=x-8;
  95.                      Move(Window->RPort,x,25L);
  96.                      Text(Window->RPort," ",1L);
  97.                      Move(Window->RPort,x,25L);
  98.                      break;
  99.                   }   
  100.                default:
  101.                   if ((code >= 32) && (code < 255))
  102.                   {
  103.                      name[i]=code;
  104.                      Text(Window->RPort,&name[i],1L);
  105.                      x=x+8L;
  106.                      i++;   
  107.                      break;
  108.                   }
  109.             }      /* end Switch*/
  110.          }         /* end VANILLAKEY if*/
  111.       }                 /* end of new message loop   */
  112.    }                    /* end of while(keepgoing)   */
  113. }                       /* end of function */
  114.  
  115. /*Final Cleanup Function*/
  116. VOID ClearWindow()
  117. {
  118.    ClearMenuStrip(Window);
  119.    CloseWindow(Window);
  120.    CloseLibrary(GfxBase);
  121.    CloseLibrary(IntuitionBase);
  122. }
  123.  
  124. /*Gets file from disk*/
  125. char load_file(infile,name)
  126.    char infile[],name[];
  127.    {
  128.       VOID filename();   
  129.       int  gile, across=7;
  130.       char *file;
  131.       filename(across);
  132.       if (name[0]==0)
  133.       {
  134.          Move(Window->RPort,7,25);
  135.          Text(Window->RPort,"                         ",25);
  136.       }
  137.       else
  138.       {
  139.          file = Open( name, MODE_OLDFILE );
  140.          if (file==0)
  141.          {
  142.             Move(Window->RPort,7,25);
  143.             Text(Window->RPort,"File Not Found           ",25);
  144.          }   
  145.          else
  146.          {
  147.             gile = Read(file, infile, 4096);
  148.             if (gile==-1)
  149.             {
  150.                Move(Window->RPort,7,25);
  151.                Text(Window->RPort,"Error Reading File       ",25);
  152.             }   
  153.          }
  154.          Close (file);
  155.       }
  156.    }
  157.  
  158. /*function to save buffer created*/
  159. char save_file(buffer,name)
  160.    char buffer[],name[];
  161.    {
  162.       VOID filename();
  163.       int gile,across=240;
  164.       char *file;
  165.       filename(across);
  166.       if (name[0]==0)
  167.       {
  168.          Move(Window->RPort,240,25);
  169.          Text(Window->RPort,"                         ",25);
  170.       }
  171.       else
  172.       {
  173.          file = Open( name, MODE_NEWFILE );
  174.          if (file==0)
  175.          {
  176.             Move(Window->RPort,240,25);
  177.             Text(Window->RPort,"Error Opening File       ",25);
  178.          }   
  179.          else
  180.          {
  181.             gile = Write(file, buffer, 4096);
  182.             if (gile==-1)
  183.             {
  184.                Move(Window->RPort,240,25);
  185.                Text(Window->RPort,"Error Writing File       ",25);
  186.             }   
  187.          }
  188.          Close (file);
  189.       }
  190.    }
  191.  
  192. /*shoves spaces into the buffer display*/
  193. char fill_buffer (buffer,buff)
  194.    char buffer[],buff[];
  195.    {
  196.       int i;
  197.       for (i=1;i<=4096;++i)
  198.          buffer[i]=' ';
  199.       for (i=1;i<=128;++i)
  200.          buff[i]=' ';
  201.    }
  202.  
  203. /*displays above*/
  204. display_empty_buffer (buffer)
  205.    char buffer[];
  206.    {   
  207.       int i=0,j=118,k=1,l=0,m=238,n=35;
  208.       int *x;
  209.       char *z,*y;
  210.       for (k=1;k<=32;k++)
  211.       {
  212.          x=&k;
  213.          z = &buffer[j];
  214.          Move(Window->RPort,(m+20),n);
  215.          Text(Window->RPort,z,10);
  216.          j=j+128;
  217.          n=n+9;
  218.          if (k==16)
  219.          {
  220.             m=353;
  221.             n=35;
  222.          }
  223.       }
  224.      }
  225.  
  226. /*displays voice names of the file opened*/
  227. display_file (infile)
  228.    char infile[];
  229.    {   
  230.       int i=0,j=118,k=1,l=0,m=5,n=35;
  231.       int *x;
  232.       char *z,*y;
  233.       for (k=1;k<=32;k++)
  234.       {
  235.          x=&k;
  236.          z = &infile[j];
  237.          Move(Window->RPort,(m+22),n);
  238.          Text(Window->RPort,z,10);
  239.          j=j+128;
  240.          n=n+9;
  241.          if (k==16)
  242.          {
  243.             m=120;
  244.             n=35;
  245.          }
  246.       }
  247.      }   
  248.  
  249. sound_to_buff(mes,win,k,a)
  250. struct IntuiMessage *mes;
  251. struct Window *win;
  252. int k, a[];
  253. {
  254.    struct Gadget *gad;
  255.    int i,j,l;
  256.    char *z;
  257.    gad = (struct Gadget *) mes->IAddress;
  258.    j = gad->GadgetID;
  259.    a[k] = j;
  260.    if (k==1)
  261.    {
  262.       for (i=1;i<=128;i++)
  263.       {
  264.          if (j<=31)
  265.             buff[i]=infile[(j)*128+i];
  266.          if (j>=32 && j<=63)
  267.             buff[i]=buffer[(j-32)*128+i];
  268.          if (j==64)
  269.             buff[i]=buff[i];      
  270.       }      
  271.       z= &buff[118];
  272.       Move(Window->RPort,222,180);
  273.       Text(Window->RPort,z,10);
  274.    }
  275.    if (k==2 && j>=32)
  276.    {
  277.       for (i=1;i<=128;i++)
  278.       {
  279.          if (j<=63)
  280.             buffer[(j-32)*128+i]=buff[i];
  281.          if (j==64)
  282.             buff[i]=buff[i];
  283.       }
  284.       z= &buff[118];
  285.       if ((j>=32) && (j<=47))
  286.       {
  287.          Move(Window->RPort,258,(26+9*(j-31)));
  288.          Text(Window->RPort,z,10);
  289.       }
  290.       if ((j>=48) && (j<=63))
  291.       {
  292.          Move(Window->RPort,373,(26+9*(j-47)));      
  293.          Text(Window->RPort,z,10);     
  294.       }
  295.    }
  296. }
  297.  
  298. /*set up the menus*/
  299. VOID InitMenu()   
  300. {
  301. /* Initialize Menu Header Whatcha wanta Do */
  302.    menu[0].NextMenu = NULL;
  303.    menu[0].LeftEdge = 5;
  304.    menu[0].TopEdge = 0;
  305.    menu[0].Width = 165;
  306.    menu[0].Height = 10;
  307.    menu[0].Flags = MENUENABLED | MIDRAWN;
  308.    menu[0].MenuName = "Selection";
  309.    menu[0].FirstItem = &menuitem[0];
  310.    
  311. /* Initialize menu item  "Dump Voices From Synth"  */
  312.    menuitem[0].NextItem = &menuitem[1];
  313.    menuitem[0].LeftEdge = 0;
  314.    menuitem[0].TopEdge = 0;
  315.    menuitem[0].Width = 156;
  316.    menuitem[0].Height = 11;
  317.    menuitem[0].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP;
  318.    menuitem[0].MutualExclude = 0xffff;
  319.    menuitem[0].ItemFill = (APTR)&menutext[0];
  320.    menuitem[0].SelectFill = NULL;
  321.    menuitem[0].Command = NULL;
  322.    menuitem[0].SubItem = NULL;
  323.    menuitem[0].NextSelect = NULL;
  324.  
  325.    menutext[0].FrontPen = 0;
  326.    menutext[0].BackPen = 1;
  327.    menutext[0].DrawMode = JAM2;
  328.    menutext[0].LeftEdge = 10;
  329.    menutext[0].TopEdge = 1;
  330.    menutext[0].ITextFont = NULL;
  331.    menutext[0].IText = (UBYTE *) "Load from disk";
  332.    menutext[0].NextText = NULL;
  333.    
  334. /* Second Menu Item  "Save Voice Buffer To Disk"  */
  335.    menuitem[1].NextItem = &menuitem[2];
  336.    menuitem[1].LeftEdge = 0;
  337.    menuitem[1].TopEdge = 11;
  338.    menuitem[1].Width = 156;
  339.    menuitem[1].Height = 11;
  340.    menuitem[1].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP;
  341.    menuitem[1].MutualExclude = 0xffff;
  342.    menuitem[1].ItemFill = (APTR) &menutext[1];
  343.    menuitem[1].SelectFill = NULL;
  344.    menuitem[1].Command = NULL;
  345.    menuitem[1].SubItem = NULL;
  346.    menuitem[1].NextSelect = NULL;
  347.    
  348.    menutext[1].FrontPen = 0;
  349.    menutext[1].BackPen = 1;
  350.    menutext[1].DrawMode = JAM2;
  351.    menutext[1].LeftEdge = 10;
  352.    menutext[1].TopEdge = 1;
  353.    menutext[1].ITextFont = NULL;
  354.    menutext[1].IText = (UBYTE *) "Save Buffer";
  355.    menutext[1].NextText = NULL;
  356.    
  357. /* Third Menu Item  "Clear the Buffer"  */
  358.    menuitem[2].NextItem = &menuitem[3];
  359.    menuitem[2].LeftEdge = 0;
  360.    menuitem[2].TopEdge = 22;
  361.    menuitem[2].Width = 156;
  362.    menuitem[2].Height = 11;
  363.    menuitem[2].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP;
  364.    menuitem[2].MutualExclude = 0xffff;
  365.    menuitem[2].ItemFill = (APTR) &menutext[2];
  366.    menuitem[2].SelectFill = NULL;
  367.    menuitem[2].Command = NULL;
  368.    menuitem[2].SubItem = NULL;
  369.    menuitem[2].NextSelect = NULL;
  370.    
  371.    menutext[2].FrontPen = 0;
  372.    menutext[2].BackPen = 1;
  373.    menutext[2].DrawMode = JAM2;
  374.    menutext[2].LeftEdge = 10;
  375.    menutext[2].TopEdge = 1;
  376.    menutext[2].ITextFont = NULL;
  377.    menutext[2].IText = (UBYTE *) "Clear Buffer";
  378.    menutext[2].NextText = NULL;
  379.    
  380. /* Initialize menu item  "Quit"  */
  381.    menuitem[3].NextItem = NULL;
  382.    menuitem[3].LeftEdge = 0;
  383.    menuitem[3].TopEdge = 33;
  384.    menuitem[3].Width = 156;
  385.    menuitem[3].Height = 11;
  386.    menuitem[3].Flags = CHECKIT | ITEMTEXT | ITEMENABLED | HIGHCOMP;
  387.    menuitem[3].MutualExclude = 0xfffe;
  388.    menuitem[3].ItemFill = (APTR)&menutext[3];
  389.    menuitem[3].SelectFill = NULL;
  390.    menuitem[3].Command = NULL;
  391.    menuitem[3].SubItem = NULL;
  392.    menuitem[3].NextSelect = NULL;
  393.    
  394.    menutext[3].FrontPen = 0;
  395.    menutext[3].BackPen = 1;
  396.    menutext[3].DrawMode = JAM2;
  397.    menutext[3].LeftEdge = 10;
  398.    menutext[3].TopEdge = 1;
  399.    menutext[3].ITextFont = NULL;
  400.    menutext[3].IText = (UBYTE *) "Quit";
  401.    menutext[3].NextText = NULL;
  402. }
  403.  
  404. main()
  405. {
  406. VOID InitMenu() , ClearWindow();
  407. ULONG class, code, menunum, itemnum, Men = 0, MenuNumber;
  408. int KeepGoing, capture, send, i, j, k=1, a[3];
  409. char load_file();
  410. static char *numbers[] =
  411. {
  412. " 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10","11","12","13","14","15","16",
  413. "17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32"
  414. };
  415.  
  416. for (i=0;i<=64;i++)
  417. {
  418. if (i == 64)
  419.    gadget[i].NextGadget = NULL;
  420. else
  421.    gadget[i].NextGadget = &gadget[i+1];
  422. if (i <=15)
  423. {
  424.    gadget[i].LeftEdge = 25;
  425.    gadget[i].TopEdge = (19+9*(i+1));
  426. }
  427. if (i >=16 && i<=31)
  428. {
  429.    gadget[i].LeftEdge = 140;
  430.    gadget[i].TopEdge = (19+9*(i-15));
  431. }
  432. if (i >=32 && i<=47)
  433. {
  434.    gadget[i].LeftEdge = 255;
  435.    gadget[i].TopEdge = (19+9*(i-31));
  436. }
  437. if (i >=48 && i <=63)
  438. {
  439.    gadget[i].LeftEdge = 370;
  440.    gadget[i].TopEdge = (19+9*(i-47));
  441. }
  442. if (i == 64)
  443. {
  444.    gadget[i].LeftEdge = 220;
  445.    gadget[i].TopEdge = 173;
  446. }
  447.    gadget[i].Width = 83;
  448.    gadget[i].Height = 9;
  449.    gadget[i].Flags = GADGHCOMP;
  450.    gadget[i].Activation = GADGIMMEDIATE | RELVERIFY;
  451.    gadget[i].GadgetType = BOOLGADGET;
  452.    gadget[i].GadgetRender =NULL;
  453.    gadget[i].SelectRender = NULL;
  454.    gadget[i].GadgetText = NULL;
  455.    gadget[i].MutualExclude = NULL;
  456.    gadget[i].SpecialInfo = NULL;
  457.    gadget[i].GadgetID = i;
  458.    gadget[i].UserData = NULL;
  459. }
  460.  
  461.    /* Open the Intuition library */
  462.  
  463. IntuitionBase = (struct IntuitionBase *)
  464. OpenLibrary("intuition.library",INTUITION_REV);
  465. if(IntuitionBase == NULL)
  466.    exit(FALSE);
  467.  
  468.    /* Open the Graphics library */
  469.  
  470. GfxBase = (struct GfxBase *)
  471. OpenLibrary("graphics.library",GRAPHICS_REV);
  472. if(GfxBase == NULL)
  473.    exit(FALSE);
  474.  
  475.    /* Open Window */
  476. if ((Window = (struct Window *) OpenWindow(&NewWindow)) == NULL)
  477.         exit(FALSE);
  478.      
  479.    /*Opens window according to structure of NewWindow (pointed to)*/
  480.  
  481.    /*  Initialize Menu items, then submit them to Intuition      */
  482. InitMenu();
  483. SetMenuStrip(Window,&menu);
  484. Move(Window->RPort,240,17);      
  485. Text(Window->RPort,"Buffer Store:" ,13);     
  486. Move(Window->RPort,140,180);      
  487. Text(Window->RPort,"Voicename:" ,10);
  488. for (i=1;i<=4096;++i)
  489.    infile[i]=' ';
  490. for (i=0;i<=15;i++)
  491.    Move(Window->RPort,5,(26+9*(i+1)));      
  492.    Text(Window->RPort,numbers[i],2);     
  493.    Move(Window->RPort,235,(26+9*(i+1)));      
  494.    Text(Window->RPort,numbers[i],2);     
  495. }
  496. for (i=16;i<=31;i++)
  497. {
  498.    Move(Window->RPort,120,(26+9*(i-15)));      
  499.    Text(Window->RPort,numbers[i],2);
  500.    Move(Window->RPort,350,(26+9*(i-15)));      
  501.    Text(Window->RPort,numbers[i],2);     
  502. }
  503. KeepGoing = 1;
  504. capture = FALSE;
  505. fill_buffer (buffer,buff);
  506. while (KeepGoing !=0)
  507. {
  508.    Wait ((1 << Window->UserPort->mp_SigBit));
  509.    while ( NewMessage=(struct IntuiMessage *)GetMsg(Window->UserPort))
  510.    {
  511.       class = NewMessage->Class;
  512.       code = NewMessage->Code;
  513.       ReplyMsg( NewMessage);
  514.       switch (class)
  515.       {
  516.                  case MENUPICK:
  517.          {
  518.          if (code !=MENUNULL)
  519.             {
  520.             menunum = MENUNUM(code);
  521.             itemnum = ITEMNUM(code);
  522.             switch (menunum)
  523.             {
  524.                  case 0:
  525.                  {
  526.                 switch (itemnum)
  527.                 {
  528.                   case 0:
  529.                    load_file (infile, name);
  530.                                display_file (infile);
  531.                   k=1;
  532.                    break;
  533.          
  534.                   case 1:
  535.                   save_file(buffer,name);
  536.                         break;
  537.  
  538.                   case 2:
  539.                         fill_buffer (buffer,buff);
  540.                   display_empty_buffer (buffer);
  541.                    break;
  542.  
  543.                   case 3:
  544.                   KeepGoing = 0;
  545.                   ClearWindow();
  546.                   Exit(0);
  547.                }            /*end switch (itemnum)*/
  548.                  }               /*end case 0 switch (menunum)*/
  549.                  break;
  550.             }           /*end switch (menunum)*/
  551.          }              /*end if code != MENUNULL*/   
  552.          }              /*end case MENUPICK*/
  553.          break;
  554.  
  555.        case GADGETUP:
  556.          sound_to_buff(NewMessage,Window,k,a);
  557.          ++k;
  558.          if (k==3)
  559.          k=1;
  560.          break;
  561.  
  562.        case GADGETDOWN:
  563.          break;
  564.  
  565.        case CLOSEWINDOW:
  566.          KeepGoing = 0;
  567.          ClearWindow();
  568.          Exit(0);
  569.          break;
  570.                        /*end case CLOSEWINDOW*/
  571.    }                        /*end switch (class)*/
  572.    }                    /*end while (newmessage etc)*/
  573. }                       /*end while (KeepGoing)*/
  574.  
  575. }
  576.  
  577.