home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / dtr / timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  6.4 KB  |  203 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/DTR/RCS/timer.c,v 1.10 92/01/09 12:43:05 drapeau Exp Locker: derek $ */
  25. /* $Log:    timer.c,v $
  26.  * Revision 1.10  92/01/09  12:43:05  drapeau
  27.  * Slight modifications to the code to make it ANSI-compliant.
  28.  * 
  29.  * Revision 1.0  92/01/06  17:51:32  drapeau
  30.  * Made a number of cosmetic changes to make code easier to read and
  31.  * to conform to programming specifications.
  32.  * 
  33.  * Revision 0.16  91/09/18  22:47:39  derek
  34.  * The following things are done:
  35.  * 1.    The Makefile is changed corresponding to the changes in collab/.
  36.  * 2.    Copyright messages included.
  37.  * 3.    Some minor bugs fixed.
  38.  * 
  39.  * Revision 0.15  91/08/21  11:34:33  derek
  40.  * The following changes are made:
  41.  * 1.    Now the duration and size of the recorded sound will be displayed
  42.  *     during recording.
  43.  * 2.    I have changed GetSelection() corresponding to the request of Tek joo
  44.  * 3.    Info Panel is added to the application.
  45.  * 4.    Fixed SizeToFitHandler() so that when no file or buffer is currently
  46.  *     loaded, it would not do anything (except giving a warning
  47.  *     notice_prompt).
  48.  * 5.    Inplemented the `Close' Menu option in the document menu.
  49.  * 6.    Fixed the bug in which after ClearAll and I press PreviewEdit,
  50.  *     the edit wont be played.
  51.  * 7.    I have made the changes corresponding to the change in OpenPanel's
  52.  *     name.  (from OpenPanel to Browse).
  53.  * 8.    Incorporated BrowseCheck to check command line arg.
  54.  * 9.    Changed most EditingStatusMessages to NoticePrompts.
  55.  * 10.    SoundFileSaveAsPopUp and EditListSaveAsPopUp are removed 
  56.  *     from the application.
  57.  * 
  58.  * Revision 0.14  91/08/13  20:38:42  derek
  59.  * The buttons (play, pause, record) will now flash after they are pressed.
  60.  * This only applies to times when audio files (not edit-lists) are 
  61.  * played.
  62.  * 
  63.  * Revision 0.13  91/08/07  16:24:50  derek
  64.  * The Edit list part of DTR is done.  OpenPanel is also incorporated.
  65.  * 
  66.  * Revision 0.12  91/06/26  15:55:56  derek
  67.  * I have reformatted the code to conform coding specs.
  68.  * 
  69.  * Revision 0.11  91/06/05  15:00:12  derek
  70.  * checking in after porting the code to collab
  71.  * 
  72.  * Revision 0.10  1991/04/25  01:53:22  derek
  73.  * This version is checked in on 4/24/91
  74.  * */
  75. static char rcsid[] = "$Header: /Source/Media/collab/DTR/RCS/timer.c,v 1.10 92/01/09 12:43:05 drapeau Exp Locker: derek $";
  76.  
  77. #include "dtr.h"
  78. #include "dtr_ui.h"
  79.  
  80. extern  dtr_mainWindow_objects *dtr_mainWindow;
  81.  
  82.  
  83. /*
  84.  * Time handler.  Entered whenever it is time to do both
  85.  * VUMeter updating and update button glowing.
  86.  */
  87. Notify_value
  88.   VUMeterTimerHandler(client, which)
  89. Notify_client client;
  90. int           which;
  91. {
  92.   EVENT("VUMeter_Timer_Handler");
  93.   
  94.   if (ActiveFlag & PLAY)
  95.     UpdateVUMeter();
  96.   return(NOTIFY_DONE);
  97. }
  98.  
  99. /*
  100.  * Set a periodic timer to poll for device open availability.  This
  101.  * timer is mainly for updating both the VUMeter and the button glow.
  102.  */
  103. void
  104.   SetVUMeterTimer(time)
  105. double time;
  106. {
  107.   static     struct itimerval    timer;
  108.   int            secs;
  109.   int            usecs;
  110.   
  111.   EVENT("Set_VUMeter_Timer");
  112.   
  113.   secs = (int)time;
  114.   usecs = (int)((time - (double)secs) * 1000000.);
  115.   
  116.   timer.it_value.tv_usec = usecs;
  117.   timer.it_value.tv_sec = secs;
  118.   timer.it_interval.tv_usec = usecs;
  119.   timer.it_interval.tv_sec = secs;
  120.   (void) notify_set_itimer_func((Notify_client)dtr_mainWindow, 
  121.                 (Notify_func)VUMeterTimerHandler,
  122.                 ITIMER_REAL, &timer, 
  123.                 ((struct itimerval *)0));
  124. }
  125.  
  126. /* 
  127.  * Cancel any outstanding periodic timer.  This is used for
  128.  * cancelling the timer which updates the VUMeter.
  129.  */
  130. void
  131.   CancelVUMeterTimer()
  132. {
  133.   EVENT("Cancel_VUMeter_Timer");
  134.   
  135.   (void) notify_set_itimer_func((Notify_client)dtr_mainWindow, 
  136.                 (Notify_func)VUMeterTimerHandler,
  137.                 ITIMER_REAL, 
  138.                 ((struct itimerval *)0), 
  139.                 ((struct itimerval *)0));
  140. }
  141.  
  142.  
  143. /*
  144.  * Button glow Time handler.  Entered whenever it is time to make the button glow.
  145.  */
  146. Notify_value
  147.   ButtonGlowTimerHandler(client, which)
  148. Notify_client client;
  149. int           which;
  150. {
  151.   EVENT("Button_Glow_Timer_Handler");
  152.   
  153.   UpdateButtonGlow();
  154.   return(NOTIFY_DONE);
  155. }
  156.  
  157. /*
  158.  * Set a periodic timer to poll for device open availability.  This
  159.  * timer is mainly for updating the Button glow.
  160.  */
  161. void
  162.   SetButtonGlowTimer(time)
  163. double time;
  164. {
  165.   static  struct itimerval    timer;
  166.   int            secs;
  167.   int            usecs;
  168.   extern  dtr_editListPanelPopUp_objects *dtr_editListPanelPopUp;
  169.   
  170.   EVENT("Set_Button_Glow_Timer");
  171.   
  172.   secs = (int)time;
  173.   usecs = (int)((time - (double)secs) * 1000000.);
  174.   
  175.   timer.it_value.tv_usec = usecs;
  176.   timer.it_value.tv_sec = secs;
  177.   timer.it_interval.tv_usec = usecs;
  178.   timer.it_interval.tv_sec = secs;
  179.   (void)notify_set_itimer_func((Notify_client)dtr_editListPanelPopUp, /*  EditListPanel  used as a dummy client to be...  */
  180.                    (Notify_func)ButtonGlowTimerHandler, /*  ...notified.                                    */
  181.                    ITIMER_REAL, &timer, 
  182.                    ((struct itimerval *)0));
  183. }
  184.  
  185. /* 
  186.  * Cancel any outstanding periodic timer.  This is used for
  187.  * cancelling the timer which updates the button color.
  188.  */
  189. void
  190.   CancelButtonGlowTimer()
  191. {
  192.   extern  dtr_editListPanelPopUp_objects *dtr_editListPanelPopUp;
  193.  
  194.   EVENT("Cancel_Button_Glow_Timer");
  195.   
  196.   (void)notify_set_itimer_func((Notify_client)dtr_editListPanelPopUp, /*  editListPanelPopUp is used as a dummy to be...  */
  197.                    (Notify_func)ButtonGlowTimerHandler, /*  ...notified.                                    */
  198.                    ITIMER_REAL, 
  199.                    ((struct itimerval *)0), 
  200.                    ((struct itimerval *)0));
  201. }
  202.  
  203.