home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / odoors50.zip / EX_MUSIC.C < prev    next >
C/C++ Source or Header  |  1994-09-24  |  5KB  |  119 lines

  1. /* EX_MUSIC.C - Example program that demonstrates how to play "ANSI" music    */
  2. /*              and sound effects in an OpenDoors door. See manual for        */
  3. /*              instructions on how to compile this program.                  */
  4.  
  5.  
  6.  
  7. #include "opendoor.h"                    /* Required in any OpenDoors program */
  8.  
  9. #include <string.h>
  10.  
  11. void play_sound(char *string);          /* Functions for playing "ANSI" music */
  12. char test_sound(void);
  13.  
  14. char sound_enabled=TRUE;     /* Variable indicates whether or not sound is on */
  15.  
  16.  
  17.  
  18. main()                                     /* Program's execution begins here */
  19.    {                                          /* Display introductory message */
  20.    od_printf("This is a simple door program that will play the song Happy Birthday\n\r");
  21.    od_printf("tune on the remote system, if the user's terminal program supports ANSI\n\r");
  22.    od_printf("music. Music is not played on the local speaker, as BBS system operators\n\r");
  23.    od_printf("do not wish to have the BBS computer making sounds at any time of the day\n\r");
  24.    od_printf("or night. However, the program can easily be modified to also echo sound to\n\r");
  25.    od_printf("the local speaker.\n\r\n\r");
  26.  
  27.  
  28.    test_sound();        /* Test whether user's terminal supports "ANSI" music */
  29.  
  30.  
  31.    od_clr_scr();                                          /* Clear the screen */
  32.    od_printf("\n\rHappy Birthday!\n\r");                 /* Display a message */
  33.  
  34.  
  35.                          /* If "ANSI" sound is available, play Happy Birthday */
  36.    play_sound("MBT120L4MFMNO4C8C8DCFE2C8C8DCGF2C8C8O5CO4AFED2T90B-8B-8AFGF2");
  37.    play_sound("00m");                   /* Reset sound after finished playing */
  38.  
  39.  
  40.    od_printf("\n\rPress any key to return to BBS...\n\r");  /* Display prompt */
  41.    od_get_key(TRUE);                          /* Wait for user to press a key */
  42.    return(0);                                                    /* Exit door */
  43.    }
  44.  
  45.  
  46.  
  47. /* Function to test whether the user's terminal program supports ANSI music.
  48.  * You can either do this every time the user uses your door, or only the first
  49.  * time they use the door, saving the result in a data file.
  50.  */
  51.  
  52. char test_sound(void)
  53.    {
  54.    char response;            /* Variable to store user's response to question */
  55.  
  56.                                        /* Display description of test to user */
  57.    od_printf("We need to know whether or not your terminal program supports ANSI music.\n\r");
  58.    od_printf("In order to test this, we will send a short ANSI music sequence. We will then\n\r");
  59.    od_printf("ask whether or not you heard any sound.\n\r");
  60.    od_printf("Press any key to begin this test... ");
  61.  
  62.    od_get_key(TRUE);                 /* Wait for user to press a key to begin */
  63.    od_printf("\n\r\n\r");
  64.  
  65.    sound_enabled=TRUE;                            /* Temporarily enable sound */
  66.    play_sound("MBT120L4MFMNO4C8C8DC");            /* Send sound test sequence */
  67.    play_sound("00m");                      /* Reset sound after finished test */
  68.  
  69.    od_clr_scr();             /* Clear screen and ask whether user heard sound */
  70.    od_printf("Did you just hear sound from your speaker? (Y/n)");
  71.    do
  72.       {
  73.       response=(char)od_get_key(TRUE);
  74.    } while (response!='y' && response!='n' && response!='Y' && response!='N');
  75.    od_printf("\n\r\n\r");
  76.  
  77.                         /* Set ANSI music on/off according to user's response */
  78.    sound_enabled = (char)(response=='y' || response=='Y');
  79.    
  80.    return(sound_enabled);
  81.    }
  82.  
  83.  
  84.  
  85. /* Function to play "ANSI" music or sound effects. The play_sound() function
  86.  * can be called with a string of 0 to 250 characters. The caracters of the
  87.  * string define what sounds should be played on the remote speaker, as
  88.  * follows:
  89.  *
  90.  *      A - G       Musical Notes
  91.  *      # or +      Following A-G note means sharp
  92.  *      -           Following A-G note means flat
  93.  *      <           Move down one octave
  94.  *      >           Move up one octave
  95.  *      .           Period acts as dotted note (extend note duration by 3/2)
  96.  *      MF          Music Foreground (pause until finished playing music)
  97.  *      MB          Music Background (continue while music plays)
  98.  *      MN          Music note duration Normal (7/8 of interval between notes)
  99.  *      MS          Music note duration Staccato
  100.  *      ML          Music note duration Legato
  101.  *      Ln          Length of note (n=1-64, 1=whole note, 4=quarter note, etc)
  102.  *      Pn          Pause length (same n values as Ln above)
  103.  *      Tn          Tempo, n=notes/minute (n=32-255, default n=120)
  104.  *      On          Octave number (n=0-6, default n=4)
  105.  */
  106.  
  107. void play_sound(char *string)
  108.    {
  109.    char musicString[255]={27,'[','\0'};        /* Beginning of music sequence */
  110.  
  111.    if(!sound_enabled) return;                /* Abort if sound is not enabled */
  112.  
  113.    strcat(musicString,string);         /* Generate sequence to send to remote */
  114.    musicString[strlen(musicString)+1]='\0';
  115.    musicString[strlen(musicString)]=0x0e;
  116.  
  117.    od_disp(musicString,strlen(musicString),FALSE);   /* Transmit the sequence */
  118.    }
  119.