home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / music / msmidi / msmidi.c next >
C/C++ Source or Header  |  1987-10-10  |  7KB  |  281 lines

  1. /* MSMIDI - Music Studio MIDI Parameter Maintenance
  2.    Written by Larry Weinheimer */
  3.  
  4. #include <osbind.h>        /* BIOS */
  5. #include <aesbind.h>        /* AES */
  6. #include <gemdefs.h>        /* GEM Definitions */
  7. #include <obdefs.h>        /* Object Structures */
  8. #include <stdio.h>        /* Standard IO */
  9. #include <msmidi.h>        /* Resource Headers */
  10.  
  11. char    channel[15],        /* channel settings */
  12.     preset[15],        /* preset settings */
  13.     range[15],        /* range setting */
  14.     ch_range[15],        /* combination channel and range */
  15.     pathbuf[66],        /* Path */
  16.     *pbuf,            /* pointer */
  17.     fname[80],        /* filename */
  18.     *fbuf,            /* pointer */
  19.     fullname[150],        /* full name */
  20.     *fullptr;        /* pointer */
  21.  
  22. int    vdi_handle,        /* vdi handle */
  23.     contrl[11],        /* vdi parameter arrays */
  24.     intin[256],
  25.     intout[45],
  26.     ptsin[256],
  27.     ptsout[12],
  28.     inf;            /* Input File */
  29.  
  30. OBJECT *tree;            /* form tree */
  31. Rect fbox={0,0,0,0};        /* and areas */
  32. Prect fboxptr={&fbox.x,&fbox.y,&fbox.w,&fbox.h};
  33. OBJECT *itree;            /* about... tree */
  34. Rect fibox={0,0,0,0};        /* and areas */
  35. Prect fiboxptr={&fbox.x,&fbox.y,&fbox.w,&fbox.h};
  36.  
  37. open_aes() {
  38.     extern int gl_apid;
  39.     int work_in[11], work_out[56];
  40.     unsigned i;
  41.     int dummy;
  42.  
  43.     appl_init();
  44.     if(gl_apid == -1) exit(1);
  45.     if(!rsrc_load("MSMIDI.RSC")) {
  46.         form_alert("[3][No MSMIDI.RSC][OH!OH!]");
  47.         exit(1);
  48.     }
  49.     vdi_handle = graf_handle(&dummy,&dummy,&dummy,&dummy);
  50.     for(i = 0; i < 10; i++) work_in [i] = 1;
  51.     work_in[10] = 2;
  52.     v_opnvwk(work_in,&vdi_handle,work_out);
  53.     if(!vdi_handle) {
  54.         form_alert("[3][VDI open failed][BUG!]");
  55.         exit(1);
  56.     }
  57.     graf_mouse(ARROW,01);
  58. }
  59.  
  60. exit_aes () {
  61.     v_clsvwk(vdi_handle);
  62.     rsrc_free();
  63.     appl_exit();
  64.     exit(0);
  65. }
  66.  
  67. bad_format () {
  68.     form_alert("[3][Not Music Studio Format][OK]");
  69. }
  70.  
  71.  
  72. get_path() {
  73.     pbuf=pathbuf;
  74.     *pbuf++=(Dgetdrv())+'A';        /* get drive */
  75.     *pbuf++=':';                /* add the ':' */
  76.     Dgetpath(pbuf,0);            /* get rest of path */
  77.     strcat(pbuf,"\\");            /* get all sng files */
  78. }
  79.  
  80. int get_file() {                /* Get the file and Open */
  81.  
  82.     int    button;                /* button */
  83.  
  84.  
  85.     pbuf=pathbuf;
  86.     strcat(pbuf,"*.SNG\0");            /* get all sng files */
  87.     fname[0]='\0';                /* clear the name */
  88.     fbuf=fname;
  89.     if(fsel_input(pbuf,fbuf,&button)==0)
  90.         return(-1);
  91.     else {    if(button==0) return(-2);
  92.         else {    fullname[0]='\0';
  93.             fullptr=fullname;
  94.             pbuf=pathbuf;
  95.             while(*pbuf!='\0') pbuf++;
  96.             while((*pbuf!='\\')&&(*pbuf!=':')) pbuf=pbuf-1;
  97.             *(pbuf+1)='\0';
  98.             pbuf=pathbuf;
  99.             strcat(fullptr,pbuf);
  100.             strcat(fullptr,fbuf);
  101.             inf=Fopen(fullptr,0);
  102.             return(0);
  103.         }
  104.     }
  105. }
  106.  
  107. long get_ted_ptr(ind) int ind; {
  108.  
  109.     return(((TEDINFO *)tree[ind].ob_spec)->te_ptext);
  110. }
  111.  
  112. out_ch(ch) int ch; {                /* set channel in form */
  113.  
  114.     sprintf(get_ted_ptr(FCH1+ch),"%2u",channel[ch]);
  115. }
  116.  
  117. get_ch(ch) int ch; {                /* get the channel in form */
  118.  
  119.     int    i;
  120.  
  121.     sscanf(get_ted_ptr(FCH1+ch),"%2d",&i);
  122.     return(i);
  123. }
  124.  
  125. out_preset(ps) int ps; {            /* set preset in form */
  126.  
  127.     sprintf(get_ted_ptr(FPS1+ps),"%3u",preset[ps]);
  128. }
  129.  
  130. get_preset(ps) int ps; {            /* get the preset in form */
  131.  
  132.     int    i;
  133.  
  134.     sscanf(get_ted_ptr(FPS1+ps),"%3d",&i);
  135.     return(i);
  136. }
  137.  
  138. out_range(rng) int rng; {            /* output range */
  139.  
  140.     sprintf(get_ted_ptr(FRANGE1+rng),"%1u",range[rng]);
  141. }
  142.  
  143. get_range(rng) int rng; {            /* get the range in form */
  144.  
  145.     int    i;
  146.  
  147.     sscanf(get_ted_ptr(FRANGE1+rng),"%1d",&i);
  148.     return(i);
  149. }
  150.  
  151. int get_data() {
  152.     char    test_hdr[8];            /* test file header area */
  153.     int    i;
  154.  
  155.     if(Fread(inf,(long)8,test_hdr)!=8) return(-1); /* get header */
  156.     if((strcmp(test_hdr,"\315Mstudio"))!=0) return(-1);
  157.  
  158.     if(Fseek((long)280,inf,0)<280) return(-1);
  159.  
  160.     for(i=FNAME1;i<FNAME1+15;i++) {        /* get 15 names */
  161.         if(Fread(inf,(long)10,get_ted_ptr(i))!=10) return(-1);
  162.     }
  163.  
  164.     if(Fread(inf,(long)15,ch_range)!=15) return(-1); /* get the channels */
  165.     for(i=0;i<15;i++) {
  166.         channel[i]=ch_range[i]&15;    /* strip out channel */
  167.         out_ch(i);            /* set them in the form */
  168.         range[i]=ch_range[i]>>4;    /* strip out range */
  169.         out_range(i);            /* set the range in the form */
  170.     }
  171.  
  172.     if(Fread(inf,(long)15,preset)!=15) return(-1); /* get the presets */
  173.     for(i=0;i<15;i++) out_preset(i);    /* set them in the form */
  174.  
  175.     if(Fseek((long)20,inf,1)<20) return(-1); /* pass the extra */
  176.  
  177.     if(Fread(inf,(long)30,get_ted_ptr(FTITLE))!=30) return(-1);
  178.                         /* set up title */
  179.  
  180.     return(Fclose(inf));
  181. }
  182.  
  183. int save_data() {
  184.  
  185.     int    i;
  186.  
  187.     fullptr=fullname;            /* get filename */
  188.     inf=Fopen(fullptr,2);
  189.     if(Fseek((long)280,inf,0)<280) return(-1);
  190.  
  191.     for(i=FNAME1;i<FNAME1+15;i++) {        /* save 15 names */
  192.         if(Fwrite(inf,(long)10,get_ted_ptr(i))!=10) return(-1);
  193.     }
  194.  
  195.     for(i=0;i<15;i++)
  196.         ch_range[i]=get_ch(i)|(get_range(i)<<4); /* get values */
  197.     if(Fwrite(inf,(long)15,ch_range)!=15) return(-1); /* save */
  198.  
  199.     for(i=0;i<15;i++) preset[i]=get_preset(i);    /* get values */
  200.     if(Fwrite(inf,(long)15,preset)!=15) return(-1); /* save presets */
  201.  
  202.     if(Fseek((long)20,inf,1)<20) return(-1); /* pass the extra */
  203.  
  204.     if(Fwrite(inf,(long)30,get_ted_ptr(FTITLE))!=30) return(-1);
  205.  
  206.     return(Fclose(inf));
  207. }
  208.  
  209. check_data() {                    /* check data on the form */
  210.  
  211.     int i;
  212.  
  213.     for(i=0;i<15;i++)
  214.         if(get_ch(i)>16||get_ch(i)<1) return (1);
  215.     for(i=0;i<15;i++)
  216.         if(get_preset(i)>127||get_preset(i)<1) return (1);
  217.     for(i=0;i<15;i++)
  218.         if(get_range(i)>5||get_range(i)<0) return (1);
  219.     return (0);
  220. }
  221.  
  222. show_info() {
  223.     rsrc_gaddr(R_TREE,FABOUT,&itree);    /* get the info form */
  224.     form_center(itree,fiboxptr);
  225.                         /* center */
  226.     form_dial(FMD_START,0,0,0,0,fibox);
  227.                         /* reserve screen area */
  228.     objc_draw(itree,ROOT,MAX_DEPTH,fibox);
  229.                         /* draw the form */
  230.     form_do(itree,0);
  231.  
  232.     form_dial(FMD_FINISH,0,0,0,0,fibox);
  233.                         /* close it up */
  234.     itree[FIDONE].ob_state&=~SELECTED;
  235.     }
  236.  
  237. do_file() {
  238.  
  239.     int    button;
  240.  
  241.     rsrc_gaddr(R_TREE,FPARAM,&tree);    /* get the form */
  242.  
  243.     if(get_data()<0) {
  244.         bad_format();
  245.         return;
  246.     }
  247.  
  248.     button=FINFO;
  249.     while(button!=FCANCEL && button!=FSAVE) {
  250.         form_center(tree,fboxptr);     /* center */
  251.         form_dial(FMD_START,0,0,0,0,fbox); /* reserve screen area */
  252.         objc_draw(tree,ROOT,MAX_DEPTH,fbox); /* draw the form */
  253.         button=form_do(tree,FTITLE);
  254.         form_center(tree,fboxptr);     /* center */
  255.         tree[button].ob_state&=~SELECTED;
  256.         if(button==FINFO) show_info();
  257.         else if(button==FSAVE)
  258.             if(check_data()>0) {
  259.                form_alert(0,
  260. "[3][Field out of Range|Channel:1-16|Presets:1-127|  Range:0-5][Fix it]");
  261.                button=FINFO;
  262.             }
  263.             else    if(save_data()>0)
  264.                    form_alert(0,"[3][Could not save Data][OK]");
  265.                 else    form_alert(0,"[0][File Saved][OK]");
  266.     }
  267. }
  268.         
  269. main () {
  270.  
  271.     int opt;
  272.  
  273.     open_aes();
  274.  
  275.     get_path();
  276.     while((opt=get_file())!=-2) {
  277.         if(opt==0) do_file();
  278.     }
  279.     exit_aes();
  280. }
  281.