home *** CD-ROM | disk | FTP | other *** search
/ IRIS Development Option 6.2 / IRIS_Development_Option_6.2_814-0478-001.iso / dist / dmedia_dev.idb / usr / include / miditime.h.z / miditime.h
C/C++ Source or Header  |  1996-03-14  |  5KB  |  171 lines

  1. /*****************************************************************************
  2.  * Copyright 1991, 1992, 1993 Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  *
  17.  ****************************************************************************/
  18.  
  19. #pragma once
  20. /*
  21.  * miditime.h
  22.  */
  23.  
  24. #ifndef __MIDITIME
  25. #define __MIDITIME
  26. #include "sys/types.h"
  27. #include "sys/time.h"
  28. #include "values.h"
  29.  
  30. /*
  31. // MMtime with conversions needed for midi.
  32.  
  33. // Time can be expressed in terms of Ppq or Smpte.
  34.  
  35. // Smpte is expressed in terms of:
  36. //    smpte rate (24, 25, drop 30, or 30
  37. //    pulses per frame
  38. //    number of pulses
  39.  
  40. // Ppq (pulses per quarternote) is expressed in terms of:
  41. //    tempo (either in usec per quarter note or in quarter notes per minute)
  42. //    pulses per quarter note
  43. //    number of pulses
  44.  
  45. // XXX Where should expression in terms of sample rate, number of samples go?
  46. */
  47.  
  48. enum SmpteFPS {
  49.     NotSmpte    = -1,
  50.     Smpte24    = 24,
  51.     Smpte25    = 25,
  52.     SmpteDrop30    = 29,
  53.     Smpte30    = 30
  54. };
  55.  
  56. enum MItimeTempoType { MItimeUsecPerQuarterNote, MItimeQuarterNotesPerMinute };
  57.  
  58. #ifdef __cplusplus
  59.  
  60. class MItime {
  61. public:
  62.     enum TempoType { UsecPerQuarterNote, QuarterNotesPerMinute };
  63.  
  64.     MItime(long hours, long minutes, long secs, long micro = 0);
  65.     MItime(long secs, long micro);
  66.     MItime(long micro = 0);
  67.     MItime(const MItime &);
  68.  
  69.     MItime(SmpteFPS rate, long ppf, long puls);            // Smpte
  70.     MItime(TempoType type, long tempo, long ppq, long puls);    // Ppq
  71.     MItime(const struct timeval &tv);
  72.  
  73.     long gethours() const;
  74.     long getminutes() const;
  75.     long getsecs() const;
  76.     long gettotalsecs() const;
  77.     long getmicros() const;
  78.  
  79.     void sethours(long /*hours*/) {}
  80.     void setminutes(long /*minutes*/) {}
  81.     void setsecs(long s) { secs = s; }
  82.     void setmicros(long u) { micros = u; }
  83.  
  84.     MItime operator-() const;
  85.  
  86.     long smpte(SmpteFPS rate, long ppf);
  87.     long ppq(TempoType type, long tempo, long Ppq);
  88.  
  89.     MItime operator+(const MItime &) const;
  90.     MItime operator-(const MItime &) const;
  91.     MItime operator*(const float) const;
  92.     MItime operator/(const float) const;
  93.     MItime operator%(int) const;
  94.     MItime &operator=(const MItime &);
  95.     MItime &operator+=(const MItime &);
  96.     MItime &operator-=(const MItime &);
  97.     MItime &operator*=(const float);
  98.     MItime &operator/=(const float);
  99.  
  100.     int operator<(const MItime &) const;
  101.     int operator<=(const MItime &) const;
  102.     int operator>(const MItime &) const;
  103.     int operator>=(const MItime &) const;
  104.     int operator==(const MItime &) const;
  105.     int operator!=(const MItime &) const;
  106.  
  107.     operator int() const;
  108.     operator long() const;
  109.     operator double() const;
  110.  
  111.     MItime currentsystemtime();
  112.  
  113.   protected:
  114.     long secs;
  115.     long micros;
  116. };
  117.  
  118. static const MItime MItimeUnknown = MItime(MAXLONG, 0);
  119. static const MItime MItimePosInfinity = MItime(MAXLONG - 1, 0);
  120. static const MItime MItimeNegInfinity = - MItimePosInfinity;
  121. static const MItime MItimeMaxInt = MItime(0, MAXINT);
  122. static const MItime MItimeMaxLong = MItime(0, MAXLONG);
  123. static const MItime MItimeZero = MItime(0);
  124. static const MItime MItime1sec = MItime(1, 0);
  125. static const MItime MItime1Min = MItime(60, 0);
  126. static const MItime MItime1Hour = MItime(3600, 0);
  127.  
  128. #else                /* __cplusplus */
  129.  
  130. typedef struct {
  131.     long opaque1;
  132.     long opaque2;
  133. } MItime;
  134.  
  135.  
  136. extern MItime MItimecreatesmpte(int, long, long);
  137. extern MItime MItimecreateppq(int, long, long, long);
  138. extern long MItimegetsmpte(MItime*, int, long);
  139. extern long MItimegetppq(MItime*, int, long, long);
  140.  
  141. extern MItime MItimecreatehours(long, long, long, long);
  142. extern MItime MItimecreatesecs(long, long);
  143. extern MItime MItimecreatemicros(long);
  144. extern MItime MItimecreate();
  145.  
  146. extern long MItimegethours(MItime*);
  147. extern long MItimegetminutes(MItime*);
  148. extern long MItimegetsecs(MItime*);
  149. extern long MItimegettotalsecs(MItime*);
  150. extern long MItimegetmicros(MItime*);
  151.  
  152. extern MItime MItimenegate(MItime*);
  153.  
  154. extern MItime MItimeadd(MItime*, MItime*);
  155. extern MItime MItimesubtract(MItime*, MItime*);
  156. extern MItime MItimemultiply(MItime*, float);
  157. extern MItime MItimedivide(MItime*, float);
  158. /* extern MItime MItimemod(MItime*, int); */
  159. extern MItime MItimecopy(MItime*, MItime*);
  160.  
  161. extern int MItimecmp(MItime*, MItime*);
  162.  
  163. extern int MItimeint(MItime*);
  164. extern long MItimelong(MItime*);
  165. extern double MItimedouble(MItime*);
  166.  
  167. extern MItime MItimecurrentsystemtime(MItime*);
  168.  
  169. #endif                /* __cplusplus */
  170. #endif                /* __MIDIIME */
  171.