home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / sound / algorhyt.lha / source / MusicTimer.c < prev    next >
C/C++ Source or Header  |  1992-02-21  |  3KB  |  141 lines

  1. /*MusicTimer.c
  2.    Copyright (c) 1990,1991,1992 by Thomas E. Janzen
  3.    All Rights Reserved
  4.  
  5.    THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
  6.    BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
  7.    CHANGES FOR FREE DISTRIBUTION.  NO TITLE TO AND OWNERSHIP OF THE
  8.    SOFTWARE IS HEREBY TRANSFERRED.  THOMAS E. JANZEN ASSUMES NO 
  9.    RESPONSBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
  10.    
  11.    Thomas E. Janzen
  12.    58A School St. Apt. 2-L
  13.    Hudson, MA 01749
  14.    (508)562-1295
  15. */
  16. /*
  17. **  FACILITY:
  18. **
  19. **    AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
  20. **    compiled with SAS/C V5.10b
  21. **
  22. **  ABSTRACT:
  23. **
  24. **    MusicTimer.c manages the timer device.
  25. **    Time is kept in a double floating-point number in seconds.
  26. **    Notes starting times are noted and when their length has passed
  27. **    they are stopped.
  28. **
  29. **  AUTHORS: Thomas E. Janzen
  30. **
  31. **  CREATION DATE:    26-MAR-1990
  32. **
  33. **  MODIFICATION HISTORY:
  34. **    DATE    NAME    DESCRIPTION
  35. **    8 DEC 91 T. Janzen conform to SAS/C 5.10b remove extern from functs
  36. **  4 Jan 92 TEJ  last changes for 2.0
  37. **--
  38. */
  39.  
  40. #include "exec/types.h"
  41. #include "exec/nodes.h"
  42. #include "exec/lists.h"
  43. #include "exec/memory.h"
  44. #include "exec/interrupts.h"
  45. #include "exec/ports.h"
  46. #include "exec/libraries.h"
  47. #include "exec/tasks.h"
  48. #include "exec/io.h"
  49. #include "exec/devices.h"
  50. #include "devices/timer.h"
  51. #include <proto/dos.h>
  52. #include <proto/graphics.h>
  53. #include <proto/exec.h>
  54. #include <proto/mathffp.h>
  55. #include <proto/intuition.h>
  56. #include "Window.h"
  57. #include "MusicTimer.h"
  58.  
  59. struct Library *TimerBase;
  60. struct timerequest *tr;
  61.  
  62. extern struct IORequest *CreateExtIO ();
  63. extern struct timerequest *CreateTimer (ULONG unit);
  64. int DeleteTimer(struct timerequest *);
  65.  
  66. struct timerequest *CreateTimer (ULONG unit)
  67. {
  68.     int error;
  69.     struct MsgPort *timerport;
  70.     struct timerequest *timermsg;
  71.  
  72.     timerport = CreatePort (NULL, 0);
  73.     if(timerport == NULL) 
  74.    {
  75.         return (NULL);
  76.     }
  77.     timermsg = (struct timerequest *)
  78.         CreateExtIO (timerport, sizeof (struct timerequest));
  79.     if(timermsg == NULL)
  80.    {
  81.         return NULL;
  82.     }
  83.     error = OpenDevice (TIMERNAME, unit, (struct IORequest *)timermsg, 0L);
  84.     if (error != 0)
  85.    {
  86.         DeleteTimer (timermsg);
  87.         return NULL;
  88.     }
  89.     return timermsg;
  90. }
  91.  
  92. int StartTimer (void)
  93. {
  94.    /* 
  95.    ** start the timer at the beginning of the program
  96.    */
  97.     tr = CreateTimer (UNIT_MICROHZ);
  98.     if (tr == 0) 
  99.    {
  100.       return -1;
  101.    }
  102.    TimerBase = (struct Library *)tr->tr_node.io_Device;
  103.     return 0;
  104. }
  105.  
  106. int GetSysTime (struct timeval *tv)
  107. {    
  108.    /* 
  109.    ** get the time in a structure
  110.    */
  111.     tr->tr_node.io_Command = TR_GETSYSTIME;
  112.     DoIO ((struct IORequest *)tr);
  113.     *tv = tr->tr_time;
  114.     return 0;
  115. }
  116.  
  117. void RemoveTimer (void) 
  118. {    
  119.    /* 
  120.    ** delete the timer at end of program 
  121.    */
  122.     DeleteTimer (tr);
  123.    return;
  124. }
  125.  
  126. int DeleteTimer (struct timerequest *tr)
  127. {
  128.     struct MsgPort *tp;
  129.     if (tr != 0)
  130.    {
  131.         tp = tr->tr_node.io_Message.mn_ReplyPort;
  132.         if (tp != 0)
  133.       {
  134.             DeletePort (tp);
  135.         }
  136.         if (tr) CloseDevice ((struct IORequest *)tr);
  137.         DeleteExtIO ((struct IORequest *)tr, sizeof (struct timerequest));
  138.     }
  139.     return 0;
  140. }
  141.