home *** CD-ROM | disk | FTP | other *** search
/ PC Loisirs 18 / cd.iso / sharewar / mikm202 / source / mikmod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-18  |  6.0 KB  |  300 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <dos.h>
  5. #include <string.h>
  6.  
  7. #include "mtypes.h"
  8. #include "wildfile.h"
  9.  
  10. #include "mloader.h"
  11. #include "mdriver.h"
  12. #include "mplayer.h"
  13.  
  14. #include "mems.h"
  15.  
  16.  
  17. char helptext[]=
  18.  
  19. "Available switches (CaSe SeNsItIvE!):\n"
  20. "\n"
  21. "  /d x    use device-driver #x for output (0 is autodetect). Default=0\n"
  22. "  /ld     List all available device-drivers\n"
  23. "  /ll     List all available loaders\n"
  24. "  /x      disables protracker extended speed\n"
  25. "  /p      disables panning effects (9fingers.mod)\n"
  26. "  /v xx   Sets volume from 0 (silence) to 100. Default=100\n"
  27. "  /f xxxx Sets mixing frequency. Default=44100\n"
  28. "  /m      Force mono output (so sb-pro can mix at 44100)\n"
  29. "  /8      Force 8 bit output\n"
  30. "  /r      Restart a module when it's done playing";
  31.  
  32.  
  33. /*
  34.     Declare external loaders:
  35. */
  36. extern LOADER mtmload,s3mload,ultload,modload,dsmload,medload,
  37.               farload,s69load,xmload,stmload,m15load,uniload;
  38.  
  39.  
  40. /*
  41.     Declare external drivers:
  42. */
  43. extern DRIVER gusdriver,sbdriver,nosnddriver;
  44.  
  45.  
  46.  
  47. /*
  48.     declarations for boring old sys-v style getopt *yawn*:
  49. */
  50. int     getopt(int argc, char *argv[], char *optionS);
  51. extern char *optarg;
  52. extern int optind;
  53. extern int opterr;
  54.  
  55.  
  56.  
  57. int breakhandler(void)
  58. {
  59.     return 1;
  60. }
  61.  
  62.  
  63. void tickhandler(void)
  64. {
  65.     MP_HandleTick();    // play 1 tick of the module
  66.     md_bpm=mp_bpm;          // and update the device bpm rate
  67. }
  68.  
  69. void HandleTimer1(void);
  70.  
  71. int main(int argc,char *argv[])
  72. {
  73.     UNIMOD *mf;
  74.     int cmderr=0;                   // error in commandline flag
  75.     int morehelp=0;                 // set if user wants more help
  76.     int quit;
  77.     int t;
  78.  
  79.     puts(mikbanner);
  80.  
  81.     //      Expand wildcards on commandline (only neccesary for MSDOS):
  82.  
  83.     MyGlob(&argc,&argv,0);
  84.  
  85.     /*
  86.         Initialize soundcard parameters.. you _have_ to do this
  87.         before calling MD_Init(), and it's illegal to change them
  88.         after you've called MD_Init()
  89.     */
  90.  
  91.     md_mixfreq      =44100;                     // standard mixing freq
  92.     md_dmabufsize   =10000;                     // standard dma buf size
  93.     md_mode         =DMODE_16BITS|DMODE_STEREO; // standard mixing mode
  94.     md_device       =0;                                                     // standard device: autodetect
  95.  
  96.     /*
  97.         Register the loaders we want to use..
  98.     */
  99.  
  100.     ML_RegisterLoader(&m15load);    // if you use m15load, register it as first!
  101.     ML_RegisterLoader(&modload);
  102.     ML_RegisterLoader(&mtmload);
  103.     ML_RegisterLoader(&farload);
  104.     ML_RegisterLoader(&s69load);
  105.     ML_RegisterLoader(&s3mload);
  106.     ML_RegisterLoader(&stmload);
  107.     ML_RegisterLoader(&dsmload);
  108.     ML_RegisterLoader(&medload);
  109.     ML_RegisterLoader(&ultload);
  110.     ML_RegisterLoader(&uniload);
  111.     ML_RegisterLoader(&xmload);
  112.  
  113.     /*
  114.         Register the drivers we want to use:
  115.     */
  116.  
  117.     MD_RegisterDriver(&nosnddriver);
  118.     MD_RegisterDriver(&sbdriver);
  119.     MD_RegisterDriver(&gusdriver);
  120.  
  121.     // Parse option switches using standard getopt function:
  122.  
  123.     opterr=0;
  124.  
  125.     while( !cmderr &&
  126.           (t=getopt(argc,argv,"ohxpm8rv:f:l:d:")) != EOF ){
  127.  
  128.         switch(t){
  129.  
  130.             case 'd':
  131.                 md_device=atoi(optarg);
  132.                 break;
  133.  
  134.             case 'l':
  135.                 if(optarg[0]=='d') MD_InfoDriver();
  136.                 else if(optarg[0]=='l') ML_InfoLoader();
  137.                 else{
  138.                     cmderr=1;
  139.                     break;
  140.                 }
  141.                 exit(0);
  142.  
  143.             case 'r':
  144.                 mp_loop=1;
  145.                 break;
  146.  
  147.             case 'm':
  148.                 md_mode&=~DMODE_STEREO;
  149.                 break;
  150.  
  151.             case '8':
  152.                 md_mode&=~DMODE_16BITS;
  153.                 break;
  154.  
  155.             case 'x':
  156.                 mp_extspd=0;
  157.                 break;
  158.  
  159.             case 'p':
  160.                 mp_panning=0;
  161.                 break;
  162.  
  163.             case 'v':
  164.                 if((mp_volume=atoi(optarg))>100) mp_volume=100;
  165.                 break;
  166.  
  167.             case 'f':
  168.                 md_mixfreq=atol(optarg);
  169.                 break;
  170.  
  171.             case 'h':
  172.                 morehelp=1;
  173.                 cmderr=1;
  174.                 break;
  175.  
  176.             case '?':
  177.                 puts("\07Invalid switch or option needs an argument\n");
  178.                 cmderr=1;
  179.                 break;
  180.         }
  181.     }
  182.  
  183.     if(cmderr || optind>=argc){
  184.  
  185.         /*
  186.             there was an error in the commandline, or there were no true
  187.             arguments, so display a usage message
  188.         */
  189.  
  190.         puts("Usage: MIKMOD [switches] <fletch.mod> ... \n");
  191.  
  192.         if(morehelp)
  193.             puts(helptext);
  194.         else
  195.             puts("Type MIKMOD /h for more help.");
  196.  
  197.         exit(-1);
  198.     }
  199.  
  200.     /*
  201.         disable control-break by
  202.         installing a custom handler, only for borland
  203.     */
  204.  
  205. #ifndef __WATCOMC__
  206.     ctrlbrk(breakhandler);
  207.     EMS_Init();
  208. #endif
  209.  
  210.     //      initialize soundcard
  211.  
  212.     if(!MD_Init()){
  213.         printf("Driver error: %s.\n",myerr);
  214.         return 0;
  215.     }
  216.  
  217.     printf("Using %s for %d bit %s sound at %u Hz\n\n",
  218.             md_driver->Name,
  219.             (md_mode&DMODE_16BITS) ? 16:8,
  220.             (md_mode&DMODE_STEREO) ? "stereo":"mono",
  221.             md_mixfreq);
  222.  
  223.  
  224.  
  225.     for(quit=0; !quit && optind<argc; optind++){
  226.  
  227.         printf("File    : %s\n",argv[optind]);
  228.  
  229.         //      load the module
  230.  
  231.         mf=ML_LoadFN(argv[optind]);
  232.  
  233.         //      didn't work -> exit with errormsg.
  234.  
  235.         if(mf==NULL){
  236.             printf("MikMod Error: %s\n",myerr);
  237.             break;
  238.         }
  239.  
  240.         //      initialize modplayer to play this module
  241.  
  242.         MP_Init(mf);
  243.  
  244.         /* tell the device-driver to call our tickhandler every 'bpm' tick */
  245.  
  246.         MD_RegisterTickHandler(tickhandler);
  247.  
  248.         printf( "Songname: %s\n"
  249.                 "Modtype : %s\n"
  250.                 "Periods : %s,%s\n",
  251.                 mf->songname,
  252.                 mf->modtype,
  253.                 (mf->flags&UF_XMPERIODS) ? "XM type" : "mod type",
  254.                 (mf->flags&UF_LINEAR) ? "Linear" : "Log");
  255.  
  256.         /*
  257.             set the number of voices to use.. you
  258.             could add extra channels here (e.g. MD_Voices(mf->numchn+4) )
  259.             to use for your own soundeffects:
  260.         */
  261.  
  262.         md_numchn=mf->numchn;
  263.  
  264.         //      start playing the module:
  265.  
  266.         MD_PlayStart();
  267.  
  268.         while(!MP_Ready()){
  269.  
  270.             char c;
  271.  
  272.             c=kbhit() ? getch() : 0;
  273.  
  274.             if(c=='+')
  275.                 MP_NextPosition();
  276.             else if(c=='-')
  277.                 MP_PrevPosition();
  278.             else if(c==0x1b){
  279.                 quit=1;
  280.                 break;
  281.             }
  282.             else if(c==' ') break;
  283.  
  284.             // wait a bit
  285.  
  286.             delay(20);
  287.             printf("\rsngpos:%d patpos:%d sngspd %d bpm %d   ",mp_sngpos,mp_patpos,mp_sngspd,mp_bpm);
  288.         }
  289.  
  290.         MD_PlayStop();          // stop playing
  291.         ML_Free(mf);            // and free the module
  292.  
  293.         puts("\n");
  294.     }
  295.  
  296.     MD_Exit();
  297.  
  298.     return 0;
  299. }
  300.