home *** CD-ROM | disk | FTP | other *** search
- /* MSMIDI - Music Studio MIDI Parameter Maintenance
- Written by Larry Weinheimer */
-
- #include <osbind.h> /* BIOS */
- #include <aesbind.h> /* AES */
- #include <gemdefs.h> /* GEM Definitions */
- #include <obdefs.h> /* Object Structures */
- #include <stdio.h> /* Standard IO */
- #include <msmidi.h> /* Resource Headers */
-
- char channel[15], /* channel settings */
- preset[15], /* preset settings */
- range[15], /* range setting */
- ch_range[15], /* combination channel and range */
- pathbuf[66], /* Path */
- *pbuf, /* pointer */
- fname[80], /* filename */
- *fbuf, /* pointer */
- fullname[150], /* full name */
- *fullptr; /* pointer */
-
- int vdi_handle, /* vdi handle */
- contrl[11], /* vdi parameter arrays */
- intin[256],
- intout[45],
- ptsin[256],
- ptsout[12],
- inf; /* Input File */
-
- OBJECT *tree; /* form tree */
- Rect fbox={0,0,0,0}; /* and areas */
- Prect fboxptr={&fbox.x,&fbox.y,&fbox.w,&fbox.h};
- OBJECT *itree; /* about... tree */
- Rect fibox={0,0,0,0}; /* and areas */
- Prect fiboxptr={&fbox.x,&fbox.y,&fbox.w,&fbox.h};
-
- open_aes() {
- extern int gl_apid;
- int work_in[11], work_out[56];
- unsigned i;
- int dummy;
-
- appl_init();
- if(gl_apid == -1) exit(1);
- if(!rsrc_load("MSMIDI.RSC")) {
- form_alert("[3][No MSMIDI.RSC][OH!OH!]");
- exit(1);
- }
- vdi_handle = graf_handle(&dummy,&dummy,&dummy,&dummy);
- for(i = 0; i < 10; i++) work_in [i] = 1;
- work_in[10] = 2;
- v_opnvwk(work_in,&vdi_handle,work_out);
- if(!vdi_handle) {
- form_alert("[3][VDI open failed][BUG!]");
- exit(1);
- }
- graf_mouse(ARROW,01);
- }
-
- exit_aes () {
- v_clsvwk(vdi_handle);
- rsrc_free();
- appl_exit();
- exit(0);
- }
-
- bad_format () {
- form_alert("[3][Not Music Studio Format][OK]");
- }
-
-
- get_path() {
- pbuf=pathbuf;
- *pbuf++=(Dgetdrv())+'A'; /* get drive */
- *pbuf++=':'; /* add the ':' */
- Dgetpath(pbuf,0); /* get rest of path */
- strcat(pbuf,"\\"); /* get all sng files */
- }
-
- int get_file() { /* Get the file and Open */
-
- int button; /* button */
-
-
- pbuf=pathbuf;
- strcat(pbuf,"*.SNG\0"); /* get all sng files */
- fname[0]='\0'; /* clear the name */
- fbuf=fname;
- if(fsel_input(pbuf,fbuf,&button)==0)
- return(-1);
- else { if(button==0) return(-2);
- else { fullname[0]='\0';
- fullptr=fullname;
- pbuf=pathbuf;
- while(*pbuf!='\0') pbuf++;
- while((*pbuf!='\\')&&(*pbuf!=':')) pbuf=pbuf-1;
- *(pbuf+1)='\0';
- pbuf=pathbuf;
- strcat(fullptr,pbuf);
- strcat(fullptr,fbuf);
- inf=Fopen(fullptr,0);
- return(0);
- }
- }
- }
-
- long get_ted_ptr(ind) int ind; {
-
- return(((TEDINFO *)tree[ind].ob_spec)->te_ptext);
- }
-
- out_ch(ch) int ch; { /* set channel in form */
-
- sprintf(get_ted_ptr(FCH1+ch),"%2u",channel[ch]);
- }
-
- get_ch(ch) int ch; { /* get the channel in form */
-
- int i;
-
- sscanf(get_ted_ptr(FCH1+ch),"%2d",&i);
- return(i);
- }
-
- out_preset(ps) int ps; { /* set preset in form */
-
- sprintf(get_ted_ptr(FPS1+ps),"%3u",preset[ps]);
- }
-
- get_preset(ps) int ps; { /* get the preset in form */
-
- int i;
-
- sscanf(get_ted_ptr(FPS1+ps),"%3d",&i);
- return(i);
- }
-
- out_range(rng) int rng; { /* output range */
-
- sprintf(get_ted_ptr(FRANGE1+rng),"%1u",range[rng]);
- }
-
- get_range(rng) int rng; { /* get the range in form */
-
- int i;
-
- sscanf(get_ted_ptr(FRANGE1+rng),"%1d",&i);
- return(i);
- }
-
- int get_data() {
- char test_hdr[8]; /* test file header area */
- int i;
-
- if(Fread(inf,(long)8,test_hdr)!=8) return(-1); /* get header */
- if((strcmp(test_hdr,"\315Mstudio"))!=0) return(-1);
-
- if(Fseek((long)280,inf,0)<280) return(-1);
-
- for(i=FNAME1;i<FNAME1+15;i++) { /* get 15 names */
- if(Fread(inf,(long)10,get_ted_ptr(i))!=10) return(-1);
- }
-
- if(Fread(inf,(long)15,ch_range)!=15) return(-1); /* get the channels */
- for(i=0;i<15;i++) {
- channel[i]=ch_range[i]&15; /* strip out channel */
- out_ch(i); /* set them in the form */
- range[i]=ch_range[i]>>4; /* strip out range */
- out_range(i); /* set the range in the form */
- }
-
- if(Fread(inf,(long)15,preset)!=15) return(-1); /* get the presets */
- for(i=0;i<15;i++) out_preset(i); /* set them in the form */
-
- if(Fseek((long)20,inf,1)<20) return(-1); /* pass the extra */
-
- if(Fread(inf,(long)30,get_ted_ptr(FTITLE))!=30) return(-1);
- /* set up title */
-
- return(Fclose(inf));
- }
-
- int save_data() {
-
- int i;
-
- fullptr=fullname; /* get filename */
- inf=Fopen(fullptr,2);
- if(Fseek((long)280,inf,0)<280) return(-1);
-
- for(i=FNAME1;i<FNAME1+15;i++) { /* save 15 names */
- if(Fwrite(inf,(long)10,get_ted_ptr(i))!=10) return(-1);
- }
-
- for(i=0;i<15;i++)
- ch_range[i]=get_ch(i)|(get_range(i)<<4); /* get values */
- if(Fwrite(inf,(long)15,ch_range)!=15) return(-1); /* save */
-
- for(i=0;i<15;i++) preset[i]=get_preset(i); /* get values */
- if(Fwrite(inf,(long)15,preset)!=15) return(-1); /* save presets */
-
- if(Fseek((long)20,inf,1)<20) return(-1); /* pass the extra */
-
- if(Fwrite(inf,(long)30,get_ted_ptr(FTITLE))!=30) return(-1);
-
- return(Fclose(inf));
- }
-
- check_data() { /* check data on the form */
-
- int i;
-
- for(i=0;i<15;i++)
- if(get_ch(i)>16||get_ch(i)<1) return (1);
- for(i=0;i<15;i++)
- if(get_preset(i)>127||get_preset(i)<1) return (1);
- for(i=0;i<15;i++)
- if(get_range(i)>5||get_range(i)<0) return (1);
- return (0);
- }
-
- show_info() {
- rsrc_gaddr(R_TREE,FABOUT,&itree); /* get the info form */
- form_center(itree,fiboxptr);
- /* center */
- form_dial(FMD_START,0,0,0,0,fibox);
- /* reserve screen area */
- objc_draw(itree,ROOT,MAX_DEPTH,fibox);
- /* draw the form */
- form_do(itree,0);
-
- form_dial(FMD_FINISH,0,0,0,0,fibox);
- /* close it up */
- itree[FIDONE].ob_state&=~SELECTED;
- }
-
- do_file() {
-
- int button;
-
- rsrc_gaddr(R_TREE,FPARAM,&tree); /* get the form */
-
- if(get_data()<0) {
- bad_format();
- return;
- }
-
- button=FINFO;
- while(button!=FCANCEL && button!=FSAVE) {
- form_center(tree,fboxptr); /* center */
- form_dial(FMD_START,0,0,0,0,fbox); /* reserve screen area */
- objc_draw(tree,ROOT,MAX_DEPTH,fbox); /* draw the form */
- button=form_do(tree,FTITLE);
- form_center(tree,fboxptr); /* center */
- tree[button].ob_state&=~SELECTED;
- if(button==FINFO) show_info();
- else if(button==FSAVE)
- if(check_data()>0) {
- form_alert(0,
- "[3][Field out of Range|Channel:1-16|Presets:1-127| Range:0-5][Fix it]");
- button=FINFO;
- }
- else if(save_data()>0)
- form_alert(0,"[3][Could not save Data][OK]");
- else form_alert(0,"[0][File Saved][OK]");
- }
- }
-
- main () {
-
- int opt;
-
- open_aes();
-
- get_path();
- while((opt=get_file())!=-2) {
- if(opt==0) do_file();
- }
- exit_aes();
- }
-