/
pos.h
134 lines (111 loc) · 4.07 KB
/
pos.h
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
//=============================================================================
// AL
// Audio Utility Library
// $Id:$
//
// Copyright (C) 2002-2009 by Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#ifndef __POS_H__
#define __POS_H__
#include "sig.h"
class TempoMap;
class TimeSigMap;
class Xml;
enum TType { TICKS, FRAMES };
//---------------------------------------------------------
// Pos
// depending on type _tick or _frame is a cached
// value. When the tempomap changes, all cached values
// are invalid. Sn is used to check for tempomap
// changes.
//---------------------------------------------------------
class Pos {
TType _type;
bool _valid;
mutable int sn;
mutable unsigned _tick;
mutable unsigned _frame;
protected:
TempoMap* tempo;
TimeSigMap* sig;
public:
Pos();
Pos(TempoMap*, TimeSigMap*);
Pos(TempoMap*, TimeSigMap*, int measure, int beat, int tick);
Pos(TempoMap*, TimeSigMap*, int minute, int sec, int frame, int subframe);
Pos(TempoMap*, TimeSigMap*, unsigned, TType type = TICKS);
Pos(TempoMap*, TimeSigMap*, const QString&);
void setContext(TempoMap* t, TimeSigMap* s) { tempo = t; sig = s; }
void dump(int n = 0) const;
unsigned time(TType t) const { return t == TICKS ? tick() : frame(); }
void mbt(int* measure, int* beat, int* tick) const;
void msf(int* minute, int* sec, int* frame, int* subframe) const;
SigEvent timesig() const;
void snap(int);
void upSnap(int);
void downSnap(int);
Pos snaped(int) const;
Pos upSnaped(int) const;
Pos downSnaped(int) const;
void invalidSn() { sn = -1; }
TType type() const { return _type; }
void setType(TType t);
Pos& operator+=(const Pos& a);
Pos& operator+=(int a);
Pos& operator-=(const Pos& a);
Pos& operator-=(int a);
bool operator>=(const Pos& s) const;
bool operator>(const Pos& s) const;
bool operator<(const Pos& s) const;
bool operator<=(const Pos& s) const;
bool operator==(const Pos& s) const;
bool operator!=(const Pos& s) const;
friend Pos operator+(const Pos& a, const Pos& b);
friend Pos operator-(const Pos& a, const Pos& b);
friend Pos operator+(const Pos& a, int b);
friend Pos operator-(const Pos& a, int b);
unsigned tick() const;
unsigned frame() const;
void setTick(unsigned);
void setFrame(unsigned);
void write(Xml&, const char*) const;
void read(QDomNode);
bool valid() const { return _valid && tempo && sig; }
void setInvalid() { _valid = false; }
};
//---------------------------------------------------------
// PosLen
//---------------------------------------------------------
class PosLen : public Pos {
mutable unsigned _lenTick;
mutable unsigned _lenFrame;
mutable int sn;
public:
PosLen(TempoMap*, TimeSigMap*);
PosLen(const PosLen&);
void dump(int n = 0) const;
void write(Xml&, const char*) const;
void read(QDomNode);
void setLenTick(unsigned);
void setLenFrame(unsigned);
unsigned lenTick() const;
unsigned lenFrame() const;
Pos end() const;
unsigned endTick() const { return end().tick(); }
unsigned endFrame() const { return end().frame(); }
void setPos(const Pos&);
bool operator==(const PosLen& s) const;
};
#endif