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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
//=========================================================
// MusE
// Linux Music Editor
// $Id: mtc.cpp,v 1.1.1.1 2003/10/27 18:51:48 wschweer Exp $
//
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=========================================================
#include "mtc.h"
#include <stdio.h>
namespace MusEGlobal {
extern int mtcType;
}
namespace MusECore {
//---------------------------------------------------------
// MTC::time
// converts MTC Time to seconds according to
// global mtcType
//---------------------------------------------------------
double MTC::time(int type) const
{
double time = _h * 3600 + _m * 60 + _s;
double ft = 0.0;
if(type == -1)
type = MusEGlobal::mtcType;
switch (type) {
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
default:
ft = 1.0/30.0;
break;
}
return time + ft *_f + 0.01 * ft * _sf;
}
//---------------------------------------------------------
// MTC
//---------------------------------------------------------
MTC::MTC(double t, int type)
{
_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;
if(type == -1)
type = MusEGlobal::mtcType;
switch (type) {
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
default:
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 type)
{
int frames = 24;
if(type == -1)
type = MusEGlobal::mtcType;
switch (type) {
case 0:
frames = 24;
break;
case 1:
frames = 25;
break;
case 2:
case 3:
default:
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);
}
} // namespace MusECore
|