File: mtc.cpp

package info (click to toggle)
muse 0.6.3-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,936 kB
  • ctags: 7,446
  • sloc: cpp: 66,262; sh: 8,355; makefile: 755; ansic: 172
file content (121 lines) | stat: -rw-r--r-- 3,008 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//=========================================================
//  MusE
//  Linux Music Editor
//  $Id: mtc.cpp,v 1.1.1.1 2003/10/29 10:05:10 wschweer Exp $
//
//  (C) Copyright 2001 Werner Schweer (ws@seh.de)
//=========================================================

#include "mtc.h"
#include <stdio.h>

extern int mtcType;

//---------------------------------------------------------
//   MTC::time
//    converts MTC Time to seconds according to
//    global mtcType
//---------------------------------------------------------

double MTC::time() const
      {
      double time = _h * 3600 + _m * 60 + _s;
      double ft = 0.0;
      switch (mtcType) {
            case 0:     // 24 frames sec
                  ft = 1.0/24.0;
                  break;
            case 1:     // 25
                  ft = 0.04;
                  break;
            case 2:     // 30 drop frame        TODO
            case 3:     // 30 non drop frame
                  ft = 1.0/30.0;
                  break;
            }
      return time + ft *_f + 0.01 * ft * _sf;
      }

//---------------------------------------------------------
//   MTC
//---------------------------------------------------------

MTC::MTC(double t)
      {
      _h  = int(t/3600);
      t -= _h * 3600;
      _m  = int(t/60);
      t -= _m * 60;
      _s  = int(t);
      t -= _s;
      double ft = 1.0/24.0;
      switch (mtcType) {
            case 0:     // 24 frames sec
                  ft = 1.0/24.0;
                  break;
            case 1:     // 25
                  ft = 0.04;
                  break;
            case 2:     // 30 drop frame
            case 3:     // 30 non drop frame
                  ft = 1.0/30.0;
                  break;
            }
      double frames = t / ft;
      _f  = int(frames);
      frames -= _f;
      _sf = int(frames * 100);
      }

//---------------------------------------------------------
//   incQuarter
//    increment MTC time one quarter frame time
//---------------------------------------------------------

void MTC::incQuarter()
      {
      int frames = 24;
      switch (mtcType) {
            case 0:
                  frames = 24;
                  break;
            case 1:
                  frames = 25;
                  break;
            case 2:
            case 3:
                  frames = 30;
                  break;
            }
      _sf += 25;
      if (_sf >= 100) {
            ++_f;
            _sf -= 100;
            }
      if (_f == frames) {
            ++_s;
            _f = 0;
            }
      if (_s == 60) {
            ++_m;
            _s = 0;
            }
      if (_m == 60) {
            ++_h;
            _m = 0;
            }
      if (_h == 24) {
            _h = 0;
            }
      }

//---------------------------------------------------------
//   print
//---------------------------------------------------------

void MTC::print() const
      {
      printf("%02d:%02d:%02d:%02d:%02d", _h, _m, _s, _f, _sf);
      }