home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / genmidi.zip / pgmnum / pgmnum.c next >
Text File  |  1995-07-19  |  2KB  |  77 lines

  1. /* PgmNum.c
  2.  *
  3.  * An example of using GENMIDI.DLL, a DLL that has functions to retrieve
  4.  * General MIDI Patch names, Drum Key names, and Controller names from
  5.  * their respective MIDI values, and vice versa.
  6.  *
  7.  * This example shows how to call the DLL function MidiGetPgmStr to retrieve
  8.  * the General MIDI Patch name for a given program number. When running
  9.  * the program, supply a number from 1 to 128 inclusive. The program will
  10.  * print the respective GM Patch name for that program number. For example,
  11.  * program #1 is "Grand Piano".
  12.  *
  13.  * Typing a number of 0 results in all 128 GM Patch names being displayed.
  14.  */
  15.  
  16. #define INCL_DOSPROCESS
  17. #define INCL_WINSTDFILE
  18. #define INCL_DOSMEMMGR
  19. #define INCL_DOSFILEMGR
  20.  
  21. #include <os2.h>
  22. #include <stdio.h>
  23. #include <conio.h>
  24. #include <string.h>
  25. #include "genmidi.h"
  26.  
  27.  
  28. /* ********************************* main() ********************************* */
  29.  
  30. VOID main(int argc, char *argv[], char *envp[])
  31. {
  32.     ULONG  pgm;
  33.     UCHAR  i;
  34.  
  35.     /* Check if any parameters were given, if not, display some help info */
  36.     if (argc < 2)
  37.     {
  38.     _cputs("Displays the General MIDI Patch Name for the specified program number.\r\n\nSyntax is '");
  39.     _cputs(argv[0]);
  40.     _cputs( " pgm'.\r\n    where pgm is a program number from 1 to 128 inclusive.\r\n");
  41.     _cputs( "    For example, program 1 is 'Grand Piano'.\r\n");
  42.     _cputs( "    Specifying a number of 0 displays all 128 GM Patch Names.\r\n\n");
  43.     _cputs("Version 1.0\r\n");
  44.     exit(0);
  45.     }
  46.  
  47.     /* Get the program number (as a binary value) */
  48.     pgm = atoi(argv[1]);
  49.  
  50.     /* Make sure that it's not > 128 */
  51.     if (pgm > 128)
  52.     {
  53.     _cputs("MIDI Program numbers must be 1 to 128 inclusive.\r\n");
  54.     exit(1);
  55.     }
  56.  
  57.     /* See if he wants all 128 GM Names displayed. If so, print 4 upon each line */
  58.     if (!pgm)
  59.     {
  60.     for (i=0; i<128; i++)
  61.     {
  62.         if (!(i%4)) _printf("\r\n");
  63.         printf("%3u %-15s", i+1, MidiGetPgmStr(i));
  64.     }
  65.     }
  66.  
  67.     /* Print just the 1 GM Name */
  68.     else
  69.     {
  70.     /* MIDI Program numbers actually must be 0 to 127, although the user normally
  71.         considers the first program to be 1 rather than 0.    Adjust for MidiGetPgmStr() */
  72.     printf("%u %s\r\n", pgm, MidiGetPgmStr(pgm-1));
  73.     }
  74.  
  75.     exit(0);
  76. }
  77.