home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / MULTIMED / MIKMOS2 / mikmod.c < prev    next >
Text File  |  1996-12-31  |  8KB  |  333 lines

  1. /*
  2.  
  3. Name:
  4. MIKMOD.C
  5.  
  6. Description:
  7. Modplaying example of mikmod.
  8.  
  9. MSDOS:    BC(y)    Watcom(y)    DJGPP(?)
  10. Win95:    BC(y*)
  11. Linux:    n
  12.  
  13. * console mode only
  14. (y) - yes
  15. (n) - no (not possible or not useful)
  16. (?) - may be possible, but not tested
  17.  
  18. */
  19. #ifdef __WIN32__
  20. #include <windows.h>
  21. #else
  22.    #ifdef __OS2__
  23.    #define INCL_DOS
  24.    #include <os2.h>
  25.    #endif
  26. #endif
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <conio.h>
  30. #include <dos.h>
  31. #include <string.h>
  32.  
  33. #include "wildfile.h"
  34. #include "mikmod.h"
  35.  
  36. char helptext[]=
  37.  
  38. "Available switches (CaSe SeNsItIvE!):\n"
  39. "\n"
  40. "  /d x    use device-driver #x for output (0 is autodetect). Default=0\n"
  41. "  /ld     List all available device-drivers\n"
  42. "  /ll     List all available loaders\n"
  43. "  /x      disables protracker extended speed\n"
  44. "  /p      disables panning effects (9fingers.mod)\n"
  45. "  /v xx   Sets volume from 0 (silence) to 100. Default=100\n"
  46. "  /f xxxx Sets mixing frequency. Default=44100\n"
  47. "  /m      Force mono output (so sb-pro can mix at 44100)\n"
  48. "  /8      Force 8 bit output\n"
  49. "  /i      Use interpolated mixing\n"
  50. "  /r      Restart a module when it's done playing";
  51.  
  52.  
  53. /*
  54.     declarations for boring old sys-v style getopt *yawn*:
  55. */
  56. int     getopt(int argc, char *argv[], char *optionS);
  57. extern char *optarg;
  58. extern int optind;
  59. extern int opterr;
  60.  
  61.  
  62. void tickhandler(void)
  63. {
  64.     MP_HandleTick();    /* play 1 tick of the module */
  65.     MD_SetBPM(mp_bpm);
  66. }
  67.  
  68.  
  69. int main(int argc,char *argv[])
  70. {
  71.     UNIMOD *mf;
  72.     int cmderr=0;                   /* error in commandline flag */
  73.     int morehelp=0;                 /* set if user wants more help */
  74.     int quit;
  75.     int t;
  76.     static int nargc;
  77.     static char **nargv;
  78. ///        int firstfileind; /* index of first file */
  79.  
  80.     puts(mikbanner);
  81.  
  82.     /*      Expand wildcards on commandline (only neccesary for MSDOS): */
  83.  
  84.     nargc=argc; nargv=argv;
  85.     MyGlob(&nargc,&nargv,0);
  86.  
  87.     /*
  88.         Initialize soundcard parameters.. you _have_ to do this
  89.         before calling MD_Init(), and it's illegal to change them
  90.         after you've called MD_Init()
  91.     */
  92.  
  93.     md_mixfreq      =44100;                     /* standard mixing freq */
  94.     md_dmabufsize   =10000;                     /* standard dma buf size */
  95.     md_mode         =DMODE_16BITS|DMODE_STEREO; /* standard mixing mode */
  96.     md_device       =0;                                                     /* standard device: autodetect */
  97.  
  98.     /*
  99.         Register the loaders we want to use..
  100.     */
  101.  
  102.     ML_RegisterLoader(&load_m15);    /* if you use m15load, register it as first! */
  103.     ML_RegisterLoader(&load_mod);
  104.     ML_RegisterLoader(&load_mtm);
  105.     ML_RegisterLoader(&load_s3m);
  106.     ML_RegisterLoader(&load_stm);
  107.     ML_RegisterLoader(&load_ult);
  108.     ML_RegisterLoader(&load_uni);
  109.     ML_RegisterLoader(&load_xm);
  110.  
  111.     /*
  112.         Register the drivers we want to use:
  113.     */
  114.  
  115.     MD_RegisterDriver(&drv_nos);
  116. #ifdef __WIN32__
  117.     MD_RegisterDriver(&drv_w95);
  118. #else
  119.    #ifdef __OS2__
  120.            MD_RegisterDriver(&drv_os2_mmpm2_smallbuffers);
  121.            MD_RegisterDriver(&drv_os2_mmpm2_largebuffers);
  122.    #else
  123.     MD_RegisterDriver(&drv_sb);
  124.     MD_RegisterDriver(&drv_gus);
  125.    #endif
  126. #endif
  127.  
  128.     MD_RegisterPlayer(tickhandler);
  129.  
  130.     /* Parse option switches using standard getopt function: */
  131.  
  132.     opterr=0;
  133.  
  134.     while( !cmderr &&
  135.           (t=getopt(nargc,nargv,"ohxpm8irv:f:l:d:")) != EOF ){
  136.  
  137.         switch(t){
  138.  
  139.             case 'd':
  140.                 md_device=atoi(optarg);
  141.                 break;
  142.  
  143.             case 'l':
  144.                 if(optarg[0]=='d') MD_InfoDriver();
  145.                 else if(optarg[0]=='l') ML_InfoLoader();
  146.                 else{
  147.                     cmderr=1;
  148.                     break;
  149.                 }
  150.                 exit(0);
  151.  
  152.             case 'r':
  153.                 mp_loop=1;
  154.                 break;
  155.  
  156.             case 'm':
  157.                 md_mode&=~DMODE_STEREO;
  158.                 break;
  159.  
  160.             case '8':
  161.                 md_mode&=~DMODE_16BITS;
  162.                 break;
  163.  
  164.             case 'i':
  165.                 md_mode|=DMODE_INTERP;
  166.                 break;
  167.  
  168.             case 'x':
  169.                 mp_extspd=0;
  170.                 break;
  171.  
  172.             case 'p':
  173.                 mp_panning=0;
  174.                 break;
  175.  
  176.             case 'v':
  177.                 if((mp_volume=atoi(optarg))>100) mp_volume=100;
  178.                 break;
  179.  
  180.             case 'f':
  181.                 md_mixfreq=atol(optarg);
  182.                 break;
  183.  
  184.             case 'h':
  185.                 morehelp=1;
  186.                 cmderr=1;
  187.                 break;
  188.  
  189.             case '?':
  190.                 puts("\07Invalid switch or option needs an argument\n");
  191.                 cmderr=1;
  192.                 break;
  193.         }
  194.     }
  195.  
  196.     if(cmderr || optind>=nargc){
  197.  
  198.         /*
  199.             there was an error in the commandline, or there were no true
  200.             arguments, so display a usage message
  201.         */
  202.  
  203.         puts("Usage: MIKMOD [switches] <fletch.mod> ... \n");
  204.  
  205.         if(morehelp)
  206.             puts(helptext);
  207.         else
  208.             puts("Type MIKMOD /h for more help.");
  209.  
  210.         exit(-1);
  211.     }
  212.  
  213.     /*  initialize soundcard */
  214.  
  215.     if(!MD_Init()){
  216.         printf("Driver error: %s.\n",myerr);
  217.         return 0;
  218.     }
  219.  
  220.     printf("Using %s for %d bit %s %s sound at %u Hz\n\n",
  221.             md_driver->Name,
  222.             (md_mode&DMODE_16BITS) ? 16:8,
  223.             (md_mode&DMODE_INTERP) ? "interpolated":"normal",
  224.             (md_mode&DMODE_STEREO) ? "stereo":"mono",
  225.             md_mixfreq);
  226.  
  227. ///        firstfileind=optind;
  228.     for(quit=0; !quit && optind<nargc; optind++){
  229.  
  230.         printf("File    : %s\n",nargv[optind]);
  231.  
  232.         /* load the module */
  233.  
  234.         mf=ML_LoadFN(nargv[optind]);
  235.  
  236.         /* didn't work -> exit with errormsg. */
  237.  
  238.         if(mf==NULL){
  239.             printf("MikMod Error: %s\n",myerr);
  240.             break;
  241.         }
  242.  
  243.         /*      initialize modplayer to play this module */
  244.  
  245.         MP_Init(mf);
  246.  
  247.         printf( "Songname: %s\n"
  248.                 "Modtype : %s\n"
  249.                 "Periods : %s,%s\n",
  250.                 mf->songname,
  251.                 mf->modtype,
  252.                 (mf->flags&UF_XMPERIODS) ? "XM type" : "mod type",
  253.                 (mf->flags&UF_LINEAR) ? "Linear" : "Log");
  254. // additional MOD-info (added by S.T.)
  255.                 printf( "\n"
  256.                         "Number of channels   : %i\n"
  257.                         "Number of positions  : %i\n"
  258.                         "Repeat position      : %i\n"
  259.                         "Number of patterns   : %i\n"
  260.                         "Number of tracks     : %i\n"
  261.                         "Number of instruments: %i\n"
  262.                         "Comment:\n%s\n",
  263.                         mf->numchn,mf->numpos,mf->reppos,mf->numpat,mf->numtrk,
  264.                         mf->numins,mf->comment);
  265.  
  266.         /*
  267.             set the number of voices to use.. you
  268.             could add extra channels here (e.g. md_numchn=mf->numchn+4; )
  269.             to use for your own soundeffects:
  270.         */
  271.  
  272.         md_numchn=mf->numchn;
  273.  
  274.         /*  start playing the module: */
  275.  
  276.         MD_PlayStart();
  277.  
  278.         while(!MP_Ready()){
  279.  
  280.             char c;
  281.  
  282.             c=kbhit() ? getch() : 0;
  283.  
  284.             if(c=='+')
  285.                         /* goto next block */
  286.                 MP_NextPosition();
  287.             else if(c=='-')
  288.                         /* goto previous block */
  289.                 MP_PrevPosition();
  290.                         /* exit player/quit program */
  291.             else if(c==0x1b){
  292.                 quit=1;
  293.                 break;
  294.             }
  295. ///                        /* added * to switch to next song S.T. */
  296. ///                        else if(c=='*')
  297. ///                           break;
  298. ///                        /* added / to switch to previous song S.T. */
  299. ///                        else if(c=='/')
  300. ///                        {
  301. ///                           if (optind>firstfileind) optind-=2;
  302. ///                           else if (optind==firstfileind) optind-=1;
  303. ///                           break;
  304. ///                        }
  305.                         /* goto next song */
  306.             else if(c==' ') break;
  307.  
  308.             MD_Update();
  309.  
  310.             /* wait a bit */
  311.  
  312. #ifdef __WIN32__
  313.             Sleep(40);
  314. #else
  315.    #ifdef __OS2__
  316.            DosSleep(40);
  317.    #else
  318.             delay(10);
  319.    #endif
  320. #endif
  321.             printf("\rsngpos:%d patpos:%d sngspd %d bpm %d   ",mp_sngpos,mp_patpos,mp_sngspd,mp_bpm);
  322.         }
  323.  
  324.         MD_PlayStop();          /* stop playing */
  325.         ML_Free(mf);            /* and free the module */
  326.  
  327.         puts("\n");
  328.     }
  329.  
  330.     MD_Exit();
  331.     return 0;
  332. }
  333.