home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / music / msplacc.arc / AMYMSP.C next >
C/C++ Source or Header  |  1989-04-16  |  18KB  |  784 lines

  1. #include <obdefs.h>
  2. #include <gemdefs.h>
  3. #include <osbind.h>
  4. #include "global.h"
  5. #include <ctype.h>
  6. #include <strings.h>
  7. #include <stdio.h>
  8. #include "mymsp.h"
  9.  
  10. /*********************************************************************/
  11. /* EXTERNALS                                    */
  12. /*********************************************************************/
  13.  
  14. extern int    gl_apid;
  15.  
  16. /*********************************************************************/
  17. /* GLOBAL VARIABLES                                */
  18. /*********************************************************************/
  19.  
  20. int    gl_hchar;
  21. int    gl_wchar;
  22. int    gl_wbox;
  23. int    gl_hbox;    /* system sizes */
  24.  
  25. int    menu_id ;    /* our menu id */
  26.  
  27. int     phys_handle;    /* physical workstation handle */
  28.  
  29. int    xdesk,ydesk,hdesk,wdesk;
  30.  
  31.  
  32. int    hidden;        /* current state of cursor */
  33. int    fulled;        /* current state of window */
  34.  
  35. int    contrl[12];
  36. int    intin[128];
  37. int    ptsin[128];
  38. int    intout[128];
  39. int    ptsout[128];    /* storage wasted for idiotic bindings */
  40.  
  41. int work_in[11];    /* Input to GSX parameter array */
  42. int work_out[57];    /* Output from GSX parameter array */
  43. int pxyarray[10];    /* input point array */
  44.  
  45. int pid;            /*    process ID number    */
  46. /*
  47.     timer externals
  48. */
  49. extern  dispatcher();    /* labels in in-line assembly must be declared. */
  50. extern  set_timer();
  51. extern  unset_timer();
  52. /*
  53.     timer globals
  54. */
  55. extern long ticks;    /* local tick counter.                    */
  56. long oldvector;            /* storage for old terminate vector.    */
  57.  
  58. EVENT_BUFFER time_out[16];
  59. ASSIGNMENT track_info[16];
  60. int current_preset[16];
  61. int track_enables[4];
  62. char *song_buffer,*song_data;
  63. long song_size;
  64. int active_song = FALSE;
  65. int default_loaded = FALSE;
  66. extern int active_timer;
  67. int time_sig,key_sig;
  68. int tempo;
  69. int event;    /*    event counter    */
  70.  
  71. char temp[120],path[80],name[20];    /*    file stuff    */
  72. char config_path[80],config_name[20];    /*    config file stuff    */
  73. char song_name[34];
  74.  
  75. char *song_ram[24];        /*    pointers to memory where songs are    */
  76. int    song_msize[24];
  77. char *song_list[24];    /*    pointers to list of songs to play    */
  78. char song_names[1000];    /*    names of the songs    */
  79. int    song_pointer = 0;    /*    current song being acted on    */
  80. int    number_of_songs = 0;    /*    total number of songs    */
  81. int    song_index = 0;
  82. int jukebox = FALSE;    /*    are we in jukebox mode    */
  83. /*
  84.     tables
  85. */
  86. extern int key_sig_tab[128];
  87. extern int s_octave[6][7];
  88. extern ASSIGNMENT track_info[16];
  89. extern int octave[6];
  90. extern int end_flag;
  91. extern int done_flag;
  92. extern int done_handshake;
  93. char rev[] = "Revision 0.90";
  94.  
  95. /****************************************************************/
  96. /*  GSX UTILITY ROUTINES.                    */
  97. /****************************************************************/
  98.  
  99. hide_mouse()
  100. {
  101.     if(! hidden){
  102.         graf_mouse(M_OFF,0x0L);
  103.         hidden=TRUE;
  104.     }
  105. }
  106.  
  107. show_mouse()
  108. {
  109.     if(hidden){
  110.         graf_mouse(M_ON,0x0L);
  111.         hidden=FALSE;
  112.     }
  113. }
  114.  
  115. /****************************************************************/
  116. /* open virtual workstation                    */
  117. /****************************************************************/
  118. int open_vwork(handle)
  119. int handle;
  120. {
  121.     int i;
  122.  
  123.     for(i=0;i<10;work_in[i++]=1);
  124.     work_in[10]=2;
  125.     v_opnvwk(work_in,&handle,work_out);
  126.     return(handle);
  127. }
  128.  
  129. /****************************************************************/
  130. /*        Accessory Init. Until First Event_Multi        */
  131. /****************************************************************/
  132. main()
  133. {
  134.     int drive;
  135.  
  136.     pid = appl_init();
  137.     phys_handle=graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  138.     menu_id=menu_register(gl_apid,"   MS Background");
  139.     wind_get(0, WF_WORKXYWH, &xdesk, &ydesk, &wdesk, &hdesk);
  140.     mrsrc_load( MYMSPRSC);
  141.     drive = Dgetdrv();
  142.     Dgetpath(path,drive+1);
  143.     sprintf(temp,"%c:%s\\",drive + 'A',path);
  144.     strcpy(path,temp);
  145.     strcpy(config_path,temp);
  146.     strcpy(config_name,"default.cfg");
  147.     init();
  148.     midi_init();
  149.     multi();
  150. }
  151.  
  152.  
  153. /****************************************************************/
  154. /* dispatches all accessory tasks                */
  155. /****************************************************************/
  156. multi()
  157. {
  158.     int event;
  159.     int vw;
  160.     int open_flag = FALSE;
  161.     int    msgbuff[8];    /* event message buffer */
  162.     int    keycode;    /* keycode returned by event-keyboard */
  163.     int    mx,my;        /* mouse x and y pos. */
  164.     int    butdown = TRUE;    /* button state tested for, UP/DOWN */
  165.     int    ret;        /* dummy return variable */
  166.  
  167.     while (TRUE)
  168.     {
  169.         event = evnt_multi(MU_MESAG | MU_BUTTON | MU_KEYBD,
  170.             1,1,butdown,
  171.             0,0,0,0,0,
  172.             0,0,0,0,0,
  173.             msgbuff,0,0,&mx,&my,&ret,&ret,&keycode,&ret);
  174.         wind_update(TRUE);
  175.         if (event & MU_MESAG)
  176.         {
  177.             switch (msgbuff[0])
  178.             {
  179.                 case AC_CLOSE:
  180.                     if((msgbuff[3] == menu_id)&&(open_flag == TRUE))
  181.                     {
  182.                         v_clsvwk(vw);
  183.                         open_flag = FALSE;
  184.                     }
  185.                     break;
  186.                 case AC_OPEN:
  187.                     if (msgbuff[4] == menu_id)
  188.                     {
  189.                         if(open_flag == FALSE)
  190.                         {
  191.                             open_flag = TRUE;
  192.                             vw = open_vwork(phys_handle);
  193.                             if(!default_loaded)
  194.                             {
  195.                                 load_config(config_path,config_name);
  196.                                 default_loaded = TRUE;
  197.                             }
  198.                             do_menu();
  199.                             v_clsvwk(vw);
  200.                             open_flag = FALSE;
  201.                           }
  202.                     }
  203.                     break;
  204.             } /* switch (msgbuff[0]) */
  205.             wind_update(FALSE);
  206.         }
  207.     } /* while (TRUE) */
  208. }
  209.  
  210. int do_dialog(dialog,start)
  211. OBJECT *dialog;
  212. int start;
  213. {
  214.     int cx,cy,cw,ch,result;
  215.  
  216.     if (dialog == (OBJECT *)(0))
  217.     {
  218.         form_alert(1,"[1][Null pointer ERROR][OK]");
  219.         return(0);
  220.     }
  221.     else
  222.     {
  223.         form_center(dialog,&cx,&cy,&cw,&ch);
  224.         form_dial(FMD_START,cx,cy,0,0,cx,cy,cw,ch);
  225.         form_dial(FMD_GROW,cx,cy,0,0,cx,cy,cw,ch);
  226.         objc_draw(dialog,0,10,cx,cy,cw,ch);
  227.         result = form_do(dialog,start);
  228.         form_dial(FMD_SHRINK,cx,cy,0,0,cx,cy,cw,ch);
  229.         form_dial(FMD_FINISH,cx,cy,0,0,cx,cy,cw,ch);
  230.         return(result);
  231.     }
  232. }
  233.  
  234.  
  235. do_menu(vw)
  236. int vw;
  237. {
  238.     int result;
  239.     OBJECT *box;
  240.     int x,y,w,h;
  241.     int i;
  242.     int dirty = TRUE;
  243.     long mem_used;
  244.  
  245.     rsrc_gaddr(R_TREE,MAINMENU,&box);
  246.     form_center(box,&x,&y,&w,&h);
  247.     if(jukebox)
  248.         box[MMLOAD].ob_state = DISABLED;
  249.     if(!active_timer)
  250.         box[MMSTOP].ob_state = DISABLED;
  251.     form_dial(FMD_START,x,y,0,0,x,y,w,h);
  252.     form_dial(FMD_GROW,x,y,0,0,x,y,w,h);
  253.     do
  254.     {
  255.         if(dirty)
  256.         {
  257.             mem_used = 0l;
  258.             for(i=0;i<24;++i)
  259.                 mem_used += (long)song_msize[i];
  260.             sprintf(temp,"%6ld",mem_used);
  261.             strcpy(box[MMEMORY].ob_spec,temp);
  262.             sprintf(temp,"%2d",number_of_songs);
  263.             strcpy(box[NUMOFSNG].ob_spec,temp);
  264.             objc_draw(box,0,10,x,y,w,h);
  265.             dirty = FALSE;
  266.         }
  267.         result = form_do(box,0);
  268.         switch(result)
  269.         {
  270.             case MMLOAD:
  271.                 if(!(box[result].ob_state & DISABLED))
  272.                 {
  273.                     if(get_file_name(path,name,"*.SNG"))
  274.                     {
  275.                         strcpy(temp,path);
  276.                         strcat(temp,name);
  277.                         song_list[number_of_songs] = (char *)&song_names[song_index];
  278.                         strcpy(song_list[number_of_songs],temp);
  279.                         song_index += strlen(song_list[number_of_songs]) +1;
  280.                         load_file(temp,number_of_songs);
  281.                         number_of_songs += 1;
  282.                         jukebox = TRUE;
  283.                     }
  284.                     objc_change(box,MMLOAD,0,x,y,w,h,NORMAL,1);
  285.                     objc_change(box,MLOADCON,0,x,y,w,h,DISABLED,1);
  286.                     objc_change(box,SONGLIST,0,x,y,w,h,DISABLED,1);
  287.                     objc_change(box,MMSTOP,0,x,y,w,h,NORMAL,1);
  288.                     dirty = TRUE;
  289.                     box[MDESTALL].ob_state = DISABLED;
  290.                 }
  291.                 break;
  292.             case MMSTOP:
  293.                 if(!(box[result].ob_state & DISABLED))
  294.                 {
  295.                     if(active_timer)
  296.                     {
  297.                         irq_dis();
  298.                         if(done_handshake)
  299.                             done_handshake = FALSE;
  300.                         irq_en();
  301.                         end_flag = TRUE;
  302.                         while(!done_handshake);    /*    wait until done    */
  303.                         done_handshake = FALSE;
  304.                         unset_timer();
  305.                     }
  306.                     objc_change(box,MMSTOP,0,x,y,w,h,NORMAL,1);
  307.                     objc_change(box,MMSTOP,0,x,y,w,h, DISABLED,1);
  308.                     objc_change(box,MMSTART,0,x,y,w,h,NORMAL,1);
  309.                 }
  310.                 break;
  311.             case MMABOUT:
  312.                 about();
  313.                 dirty = TRUE;
  314.                 box[MMABOUT].ob_state = NORMAL;
  315.                 break;
  316.             case SONGLIST:
  317.                 if(!(box[result].ob_state & DISABLED))
  318.                 {
  319.                     get_song_list();
  320.                     box[MDESTALL].ob_state = DISABLED;
  321.                     box[SONGLIST].ob_state = NORMAL;
  322.                     jukebox = TRUE;
  323.                     dirty = TRUE;
  324.                 }
  325.                 break;
  326.             case MMSTART:
  327.                 if(!(box[result].ob_state & DISABLED))
  328.                 {
  329.                     song_buffer = song_ram[song_pointer];
  330.                     do_perform(vw);
  331.                     objc_change(box,MMSTART,0,x,y,w,h,NORMAL,1);
  332.                     objc_change(box,MMSTART,0,x,y,w,h, DISABLED,1);
  333.                     objc_change(box,MMSTOP,0,x,y,w,h,NORMAL,1);
  334.                 }
  335.                 break;
  336.             case MSAVECON:
  337.                 save_config();
  338.                 box[result].ob_state = NORMAL;
  339.                 dirty = TRUE;
  340.                 break;
  341.             case MCLEAR:
  342.                 if(!(box[result].ob_state & DISABLED))
  343.                 {
  344.                     if(active_timer)
  345.                     {
  346.                         irq_dis();
  347.                         if(done_handshake)
  348.                             done_handshake = FALSE;
  349.                         irq_en();
  350.                         end_flag = TRUE;    /*    stop everything first    */
  351.                         while(!done_handshake);    /*    wait until done    */
  352.                         done_handshake = FALSE;
  353.                         objc_change(box,MMSTOP,0,x,y,w,h,NORMAL,1);
  354.                         objc_change(box,MMSTOP,0,x,y,w,h, DISABLED,1);
  355.                         objc_change(box,MMSTART,0,x,y,w,h,NORMAL,1);
  356.                         unset_timer();
  357.                     }
  358.                     for(i=0;i<24;++i)
  359.                     {
  360.                         if(song_ram[i] != NULL)
  361.                         {
  362.                             Mfree(song_ram[i]);
  363.                             song_ram[i] = NULL;
  364.                             song_list[i] = NULL;
  365.                             song_msize[i] = 0;
  366.                         }
  367.                     }
  368.                     song_pointer = 0;
  369.                     jukebox = FALSE;
  370.                     number_of_songs = 0;
  371.                     song_index = 0;
  372.                     active_song = FALSE;
  373.                     objc_change(box,MMLOAD,0,x,y,w,h,NORMAL,1);
  374.                     objc_change(box,MLOADCON,0,x,y,w,h,NORMAL,1);
  375.                     objc_change(box,SONGLIST,0,x,y,w,h,NORMAL,1);
  376.                     objc_change(box,MDESTALL,0,x,y,w,h,NORMAL,1);
  377.                     objc_change(box,MCLEAR,0,x,y,w,h,NORMAL,1);
  378.                     dirty = TRUE;
  379.                 }
  380.                 break;
  381.             case MLOADCON:
  382.                 if(!(box[result].ob_state & DISABLED))
  383.                 {
  384.                     if(get_file_name(config_path,config_name,"*.CFG"))
  385.                     {
  386.                         load_config(config_path,config_name);
  387.                     }
  388.                     dirty = TRUE;
  389.                 }
  390.                 objc_change(box,MLOADCON,0,x,y,w,h,NORMAL,1);
  391.                 box[MLOADCON].ob_state = DISABLED;
  392.                 box[MDESTALL].ob_state = DISABLED;
  393.                 break;
  394.             case MINSTALL:
  395.                 if(!(box[result].ob_state & DISABLED))
  396.                 {
  397.                     init_traps();    /*    install MIDI trap vector    */
  398.                     init_vecs();    /*    change key/midi irq vector    */
  399.                     objc_change(box,MINSTALL,0,x,y,w,h,NORMAL,1);
  400.                     objc_change(box,MINSTALL,0,x,y,w,h,DISABLED,1);
  401.                     objc_change(box,MMLOAD,0,x,y,w,h,NORMAL,1);
  402.                     objc_change(box,MLOADCON,0,x,y,w,h,NORMAL,1);
  403.                     objc_change(box,SONGLIST,0,x,y,w,h,NORMAL,1);
  404.                     objc_change(box,MMSTART,0,x,y,w,h,NORMAL,1);
  405.                     objc_change(box,MCLEAR,0,x,y,w,h,NORMAL,1);
  406.                 }
  407.                 break;
  408.             case MDESTALL:
  409.                 if(!(box[result].ob_state & DISABLED))
  410.                 {
  411.                     if(!active_timer)
  412.                         unset_timer();    /*    disable the timer    */
  413.                     midi_cleanup();        /*    restore TRAP 3 and interrupt vector    */
  414.                     objc_change(box,MINSTALL,0,x,y,w,h,NORMAL,1);
  415.                     objc_change(box,MDESTALL,0,x,y,w,h,NORMAL,1);
  416.                     objc_change(box,MDESTALL,0,x,y,w,h,DISABLED,1);
  417.                     objc_change(box,MMLOAD,0,x,y,w,h,DISABLED,1);
  418.                     objc_change(box,MLOADCON,0,x,y,w,h,DISABLED,1);
  419.                     objc_change(box,SONGLIST,0,x,y,w,h,DISABLED,1);
  420.                     objc_change(box,MMSTART,0,x,y,w,h,DISABLED,1);
  421.                     objc_change(box,MCLEAR,0,x,y,w,h,DISABLED,1);
  422.                 }
  423.                 break;
  424.             case MMCAN:
  425.                 break;
  426.         }    /*    end of switch result    */
  427.     }while (result != MMCAN);
  428.     box[result].ob_state = NORMAL;
  429.     form_dial(FMD_SHRINK,x,y,0,0,x,y,w,h);
  430.     form_dial(FMD_FINISH,x,y,0,0,x,y,w,h);
  431. }
  432.  
  433. get_song_list()
  434. {
  435.     OBJECT *box;
  436.     int x,y,h,w;
  437.     int save;
  438.     char *ptr;
  439.     register int i;
  440.     int result;
  441.  
  442.     save = song_pointer;
  443.     song_pointer = number_of_songs;
  444.     rsrc_gaddr(R_TREE,SNGLIST,&box);
  445.     form_center(box,&x,&y,&w,&h);
  446.     form_dial(FMD_START,x,y,0,0,x,y,w,h);
  447.     form_dial(FMD_GROW,x,y,0,0,x,y,w,h);
  448.     do
  449.     {
  450.         objc_draw(box,0,10,x,y,w,h);
  451.         result = form_do(box,0);
  452.         switch(result)
  453.         {
  454.             case SLEXIT:
  455.                 break;
  456.             case SLFIND:
  457.                 if(get_file_name(path,name,"*.SNG"))
  458.                 {
  459.                     ptr = (char *)(&song_names[song_index]);
  460.                     song_list[song_pointer] = ptr;
  461.                     for(i=0;path[i] != '\0';++i,++ptr)
  462.                         *ptr = path[i];
  463.                     song_index += i;
  464.                     for(i=0;name[i] != '\0';++i,++ptr)
  465.                         *ptr = name[i];
  466.                     *ptr = '\0';
  467.                     load_file(song_list[song_pointer],song_pointer);
  468.                     ++song_pointer;
  469.                     song_index += i + 1;
  470.                     if(song_pointer > 23)
  471.                     {
  472.                         box[SLFIND].ob_state = NORMAL;
  473.                         box[SLFIND].ob_state |= DISABLED;
  474.                     }
  475.                 }
  476.                 break;
  477.         }    /*    end of switch result    */
  478.         box[result].ob_state = NORMAL;
  479.     }while (result != SLEXIT);
  480.     number_of_songs = song_pointer;
  481.     song_pointer = save;
  482.     form_dial(FMD_SHRINK,x,y,0,0,x,y,w,h);
  483.     form_dial(FMD_FINISH,x,y,0,0,x,y,w,h);
  484. }
  485.  
  486.     
  487. gen_key_tab(key)
  488. int key;
  489. {
  490.     register int i;
  491.  
  492.     for(i=0;i<128;++i)
  493.         key_sig_tab[i] = 0;
  494.     if( key == CMAJ )
  495.         return;    /*    nothing to do    */
  496.     if(key <= CSMAJ)    /*    these all generate sharps    */
  497.     {
  498.         switch(key)
  499.         {
  500.             case CSMAJ:
  501.                 for(i=11;i<128;i += 12)
  502.                     key_sig_tab[i] = 1;
  503.             case FSMAJ:
  504.                 for(i=4;i<128;i += 12)
  505.                     key_sig_tab[i] = 1;
  506.             case BMAJ:
  507.                 for(i = 9;i<128;i += 12)
  508.                     key_sig_tab[i] = 1;
  509.             case EMAJ:
  510.                 for(i = 2;i < 128;i += 12)
  511.                     key_sig_tab[i] = 1;
  512.             case AMAJ:
  513.                 for(i = 7;i < 128;i += 12)
  514.                     key_sig_tab[i] = 1;
  515.             case DMAJ:
  516.                 for(i=0;i < 128;i += 12)
  517.                     key_sig_tab[i] = 1;
  518.             case GMAJ:
  519.                 for(i=5;i<128;i += 12)
  520.                     key_sig_tab[i] = 1;
  521.         }
  522.     }
  523.     else    /*    these all generate flats    */
  524.     {
  525.         switch(key)
  526.         {
  527.             case CFMAJ:
  528.                 for(i=5;i < 128;i +=12)
  529.                     key_sig_tab[i] = -1;
  530.             case GFMAJ:
  531.                 for(i=0;i < 128;i +=12)
  532.                     key_sig_tab[i] = -1;
  533.             case DFMAJ:
  534.                 for(i=7;i < 128;i +=12)
  535.                     key_sig_tab[i] = -1;
  536.             case AFMAJ:
  537.                 for(i=2;i < 128;i +=12)
  538.                     key_sig_tab[i] = -1;
  539.             case EFMAJ:
  540.                 for(i=9;i < 128;i +=12)
  541.                     key_sig_tab[i] = -1;
  542.             case BFMAJ:
  543.                 for(i=4;i < 128;i +=12)
  544.                     key_sig_tab[i] = -1;
  545.             case FMAJ:
  546.                 for(i = 11;i < 128;i +=12)
  547.                     key_sig_tab[i] = -1;
  548.         }
  549.     }
  550. }
  551.             
  552. load_file(n,i)
  553. char *n;
  554. int i;
  555. {
  556.     int fd;    /*    file descriptor for input file    */
  557.     DTA    file_info;
  558.     long old_dta;
  559.  
  560.     if(song_ram[i] != NULL)
  561.     {
  562.         Mfree(song_ram[i]);    /*    free up if used    */
  563.         song_msize[i] = 0;
  564.     }
  565.     old_dta = (long)Fgetdta();    /*    save the old DTA    */
  566.     Fsetdta(&file_info);    /*    set address    */
  567.     Fsfirst(n,0);    /*    get file info    */
  568.     song_msize[i] = (int)file_info.fsize;
  569.     song_ram[i] = (char *)Malloc(file_info.fsize);    /* allocate memory for file    */
  570.     fd = Fopen(n,0);    /*    open file for read    */
  571.     song_size = Fread(fd,file_info.fsize,song_ram[i]);    /*    read data    */
  572.     Fclose(fd);    /*    close file    */
  573.     active_song = TRUE;
  574.     Fsetdta(old_dta);
  575. }
  576.  
  577. get_file_name(p,n,spec)
  578. char p[],n[],spec[];
  579. {
  580.     int but;
  581.     int done;
  582.     char *ptr;
  583.     int status;
  584.  
  585.     done = FALSE;
  586.     do
  587.     {
  588.         strcpy(temp,p);
  589.         strcat(temp,spec);
  590.         fsel_input(temp,n,&but);
  591.         if(but == 1)    /*    ok    */
  592.         {
  593.             if((ptr = (char *)index(temp,'*')) != NULL)
  594.             {
  595.                 *ptr = '\0';
  596.                 strcpy(p,temp);
  597.             }
  598.             done = TRUE;
  599.             status = TRUE;
  600.         }
  601.         else
  602.         {
  603.             status = FALSE;
  604.             done = TRUE;
  605.         }
  606.     }while(!done);
  607.     return(status);
  608. }
  609.  
  610. init_buffer()
  611. {
  612.     register int i;
  613.  
  614.     for(i=0;i<16;++i)
  615.     {
  616.         time_out[i].channel = 0;
  617.         time_out[i].duration = 0;
  618.         time_out[i].note = 0;
  619.         time_out[i].tie_beg = 0;
  620.         time_out[i].tie_end = 0;
  621.         time_out[i].in_use_flag = 0;
  622.         time_out[i].rest = 0;
  623.         time_out[i].velocity = 0;
  624.         current_preset[i] = -1;
  625.     }
  626. }
  627.  
  628. get_song_parameters()
  629. {
  630.     register int i;
  631.     MIDI_INFO *inf;
  632.     char t[100];
  633.  
  634.     inf = (MIDI_INFO *)&song_buffer[0x118];
  635.     for(i=1;i<16;++i)
  636.     {
  637.         track_info[i].channel = ((int)((inf->chan_range[i-1]) & 0x0f) - 1) & 0x0f;
  638.         track_info[i].octave_num = (int)((inf->chan_range[i-1]) >> 4);
  639.         track_info[i].octave = octave[track_info[i].octave_num];
  640.         track_info[i].patch = (int)(inf->patch[i-1]);
  641.  
  642. /*        sprintf(t,"[1][CH: %d|OCTV: %d|PTCH: %d|INDX: %d][OK]",
  643.             track_info[i].channel,track_info[i].octave,track_info[i].patch,i);
  644.         form_alert(1,t);    */
  645.     }
  646.     strcpy(song_name,inf->name);    /*    copy song name    */
  647. }
  648.  
  649. get_note(note_str,note)
  650. int note;
  651. char note_str[];
  652. {
  653.     /*
  654.         returns a formated string representing the break point
  655.     */
  656.     int a,b;
  657.     char tmp[5];
  658.  
  659.     a = note / 12;
  660.     b = note % 12;
  661.  
  662.     switch(b)
  663.     {
  664.         case 0:
  665.             strcpy(note_str,"C ");
  666.             break;
  667.         case 1:
  668.             strcpy(note_str,"C#");
  669.             break;
  670.         case 2:
  671.             strcpy(note_str,"D ");
  672.             break;
  673.         case 3:
  674.             strcpy(note_str,"D#");
  675.             break;
  676.         case 4:
  677.             strcpy(note_str,"E ");
  678.             break;
  679.         case 5:
  680.             strcpy(note_str,"F ");
  681.             break;
  682.         case 6:
  683.             strcpy(note_str,"F#");
  684.             break;
  685.         case 7:
  686.             strcpy(note_str,"G ");
  687.             break;
  688.         case 8:
  689.             strcpy(note_str,"G#");
  690.             break;
  691.         case 9:
  692.             strcpy(note_str,"A ");
  693.             break;
  694.         case 10:
  695.             strcpy(note_str,"A#");
  696.             break;
  697.         case 11:
  698.             strcpy(note_str,"B ");
  699.             break;
  700.     }
  701.         sprintf(tmp," %1d",a);
  702.         strcat(note_str,tmp);
  703. }
  704.  
  705. Set_Tempo()
  706. {
  707.     *((char *)0xfffa1f) = tempo;
  708. }
  709.  
  710. about()
  711. {
  712.     OBJECT *box;
  713.     int ret;
  714.  
  715.     rsrc_gaddr(R_TREE,ABOUT,&box);
  716.     strcpy(box[ABREV].ob_spec,rev);
  717.     ret = do_dialog(box,0);
  718.     box[ret].ob_state = NORMAL;
  719. }
  720.  
  721. init()
  722. {
  723.     int i;
  724.  
  725.     strcpy(s_octave[0]," 0- 60");
  726.     strcpy(s_octave[1],"12- 72");
  727.     strcpy(s_octave[2],"24- 84");
  728.     strcpy(s_octave[3],"36- 96");
  729.     strcpy(s_octave[4],"48-108");
  730.     strcpy(s_octave[5],"60-120");
  731.     for(i=0;i<24;++i)
  732.     {
  733.         song_list[i] = NULL;    /*    null out song list    */
  734.         song_ram[i] = NULL;
  735.         song_msize[i] = 0;
  736.     }
  737. }
  738.  
  739. load_config(p,n)
  740. char p[];    /*    path of config file    */
  741. char n[];    /*    name of config file    */
  742. {
  743.     FILE    *config;
  744.     char name[80];
  745.     int i;
  746.     int num;
  747.  
  748.     song_index = 0;
  749.     strcpy(name,p);
  750.     strcat(name,n);    /*    make file name    */
  751.     if((config = fopen(name,"r")) == NULL)
  752.         return(-1);        /*    no config file, so just return    */
  753.     fscanf(config,"%d\n",&num);    /*    get number of items    */
  754.     for(i=0;i<num;++i)
  755.     {
  756.         song_list[i] = (char *)&song_names[song_index];
  757.         fscanf(config,"%s\n",song_list[i]);    /*    get a name    */
  758.         song_index += strlen(song_list[i]) + 1;
  759.         load_file(song_list[i],i);
  760.     }
  761.     fclose(config);
  762.     number_of_songs = num;
  763.     jukebox = TRUE;
  764.     song_pointer = 0;
  765. }
  766.  
  767. save_config()
  768. {
  769.     FILE *config;
  770.     int i;
  771.  
  772.     if(get_file_name(config_path,config_name,"*.CFG"))
  773.     {
  774.         strcpy(temp,config_path);
  775.         strcat(temp,config_name);
  776.         if((config = fopen(temp,"w")) == NULL)
  777.             return;
  778.         fprintf(config,"%d\n",number_of_songs);
  779.         for(i=0;i<number_of_songs;++i)
  780.             fprintf(config,"%s\n",song_list[i]);
  781.         fclose(config);
  782.     }
  783. }
  784.