home *** CD-ROM | disk | FTP | other *** search
/ Dr. CD ROM (Annual Premium Edition) / premium.zip / premium / IBMOS2_1 / CDTRACK.ZIP / cdtrack.c next >
Text File  |  1993-05-11  |  7KB  |  205 lines

  1. /**************************************************************************** 
  2.  *
  3.  *   GLORY:
  4.  *
  5.  *   CDTRACK.C  0.01    Joseph Chiu, California Institute of Technology
  6.  *                      Mail Box 380, Caltech, Pasadena, California 91126
  7.  *   Written 5/11/93    josephc@legend.caltech.edu, josephc@cco.caltech.edu
  8.  *                      (818) 449 5457          Compu$pend: 72113,2105
  9.  *   
  10.  *   CDTRACK, Copyright (C) 1993, Joseph Chiu, All Rights Reserved
  11.  *
  12.  *   Send me E-mail!  I'd like to hear from ya!
  13.  *   (Bug fixes, suggestions, and usage anecdotes are very welcome!)
  14.  *
  15.  ****************************************************************************
  16.  *
  17.  *   INFO:
  18.  *
  19.  *   CDTRACK : Command line CD-player
  20.  *
  21.  *   Format:  CDTRACK <start> <stop>
  22.  *
  23.  *      where <start> and <stop> are track numbers.
  24.  *
  25.  *      if parameters are not given, CDTRACK will default to play track 1 only.
  26.  *      if only <start> is given, CDTRACK will play that track only.
  27.  *
  28.  ****************************************************************************
  29.  *
  30.  *   LEGALESE:
  31.  *
  32.  *   This program is Freeware.  There is no fee for the use of this software;
  33.  *   the author only asks that you send him e-mail if you find this software
  34.  *   useful, or have ideas for improvements.  The author of this software makes
  35.  *   no expressed or implied warranty of any kind with regards to this software
  36.  *   and in no event will be liable for incidental or consequential damages
  37.  *   arising from the use of this product, even if the author has been advised
  38.  *   of the possibility of said damages. (Ah, the worries in sue-happy U.S.A.!)
  39.  *
  40.  ****************************************************************************
  41.  *
  42.  *  HISTORY:
  43.  *   
  44.  *  11-May-93  First release of CDTRACK.  Version number 0.01 because there's
  45.  *             a lot more to go before it can even be called a product.
  46.  *             Compiled under CSet++/2 March Beta
  47.  *
  48.  ****************************************************************************
  49.  *
  50.  * NOTES:
  51.  *
  52.  * If you get an error 'mciSendString - unresolved external', you need to make
  53.  * sure that you have included the MMPM2 library in the library path, and/or
  54.  * that it is specifically "given" to the linker
  55.  *
  56.  * This program is for command-line use only.  If you want a 'nice' PM-based
  57.  * CD-player, get CDEXPL (CD-Explorer).  It is a much better product for end-
  58.  * users than this program will ever be.
  59.  *
  60.  * To-Do:  Allow communicating via named pipes or queues to allow the parent
  61.  * process to control CD-Track's behaviour (e.g., force CD-Track to stop early),
  62.  * and put in 'Verbose' mode [yanked out, pending improvements].
  63.  * 
  64.  * "OS/2 is my programming environment of choice.  It allows me to break free
  65.  *  from the constraints of the DOS+Windows environment." --Joseph Chiu.
  66.  */
  67.  
  68. #include <os2.h>
  69. #include <stdio.h>
  70. #include <os2me.h>
  71.  
  72. #define STRING_SIZE 128
  73. #define MCI_STRING_LENGTH 128
  74.  
  75. main(int argc, char *argv[], char *envp[])
  76. {
  77.    CHAR acTempString [STRING_SIZE],       /* Used to store command strings  */
  78.         acMCIString [MCI_STRING_LENGTH];  /* Used for notification messages */
  79.  
  80.    LONG lSendStringRC = 0;                /* return code from mciSendString */
  81.  
  82.    int  trackstart,                       /* Starting and ending track #'s  */
  83.         trackend;   
  84.  
  85.  
  86.    if (argc > 1) {                        /* Get start/stop track numbers */
  87.       trackstart = atoi (argv[1]);
  88.       if (trackstart < 1)
  89.          trackstart = 1;
  90.    } else {
  91.       trackstart = 1;
  92.    } /* endif */
  93.  
  94.    if (argc <= 2) {
  95.       trackend = trackstart;
  96.    } else {
  97.       trackend = atoi(argv[2]);
  98.       if (trackend < trackstart)
  99.         trackend = trackstart;
  100.    } /* endif */
  101.  
  102.  
  103.  
  104. /***  Open the CDROM Drive for use with this program */
  105.  
  106.    strcpy (acTempString, "open cdaudio wait");
  107.    lSendStringRC =
  108.         mciSendString (
  109.                 (LPSTR) &acTempString[0],   /* The command to the MM-API */
  110.                 (LPSTR) NULL,               /* We don't expect an answer */
  111.                 (WORD) 0,                   /* 0-length return string */
  112.                 0,                          /* Do not notify any window */
  113.                 0);                         /* User Parameter */
  114.  
  115.    if (lSendStringRC != MCIERR_SUCCESS)
  116.       return -1;
  117.  
  118.  
  119. /*** Set the CDROM Drive to use the Track:Minute:Second:Frame format */
  120.  
  121.    strcpy (acTempString, "set cdaudio time format tmsf wait");
  122.  
  123.    lSendStringRC =
  124.         mciSendString (
  125.                 (LPSTR) &acTempString[0],   
  126.                 (LPSTR) NULL,  
  127.                 (WORD) 0, 
  128.                 0,            
  129.                 0);       
  130.  
  131.    if (lSendStringRC != MCIERR_SUCCESS)
  132.       return -1;
  133.  
  134.  
  135. /*** Get the length of the last track's length in minute:second:frame format */
  136.  
  137.    sprintf (acTempString, "status cdaudio length track %d wait", trackend);
  138.    lSendStringRC =
  139.         mciSendString (
  140.                 (LPSTR) &acTempString[0],  /* The command */
  141.                 (LPSTR) &acMCIString[0],   /* Place to put return string */
  142.                 (WORD) MCI_STRING_LENGTH,  /* The size of the return space */
  143.                 0,                         /* No notifies */
  144.                 0);           
  145.  
  146.    if (lSendStringRC != MCIERR_SUCCESS)
  147.       return -1;
  148.  
  149.  
  150. /*** Play from the start-track to the end of the stop-track  */
  151.  
  152.    sprintf (acTempString, "play cdaudio from %02d:00:00:00 to %02d:%s wait",
  153.                 trackstart, trackend, acMCIString);
  154.  
  155.    lSendStringRC =
  156.         mciSendString (
  157.                 (LPSTR) &acTempString[0],        /* The command */
  158.                 (LPSTR) NULL,  /* Place to put return string */
  159.                 (WORD) 0, /* How large is the return space */
  160.                 0,            /* Which window receives notifies */
  161.                 0);       /* User Parameter */
  162.  
  163.    if (lSendStringRC != MCIERR_SUCCESS)
  164.       return -1;
  165.  
  166.  
  167.  
  168. /***  Stop the CDROM drive */   
  169.  
  170.    strcpy (acTempString, "stop cdaudio");
  171.    lSendStringRC =
  172.         mciSendString (
  173.                 (LPSTR) &acTempString[0],
  174.                 (LPSTR) NULL,  
  175.                 (WORD) 0, 
  176.                 0,
  177.                 0);
  178.  
  179.    if (lSendStringRC != MCIERR_SUCCESS)
  180.       return -1;
  181.  
  182.  
  183. /***  Close the CDROM drive */
  184.  
  185.    strcpy (acTempString, "close cdaudio wait");
  186.  
  187.    lSendStringRC =
  188.         mciSendString (
  189.                 (LPSTR) &acTempString[0],        /* The command */
  190.                 (LPSTR) NULL,  /* Place to put return string */
  191.                 (WORD) 0, /* How large is the return space */
  192.                 0,            /* Which window receives notifies */
  193.                 0);       /* User Parameter */
  194.  
  195.    if (lSendStringRC != MCIERR_SUCCESS)
  196.       return -1;
  197.  
  198.  
  199. /*** Success! */
  200.  
  201.    return 0;
  202. }
  203.  
  204.  
  205.