MuseScore  3.4
Music composition and notation
pos.h
Go to the documentation of this file.
1 //=============================================================================
2 // AL
3 // Audio Utility Library
4 //
5 // Copyright (C) 2002-2009 by Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __POS_H__
21 #define __POS_H__
22 
23 #include "sig.h"
24 
25 namespace Ms {
26 
27 class TempoMap;
28 class TimeSigMap;
29 class XmlWriter;
30 class XmlReader;
31 
32 enum class TType : char { TICKS, FRAMES };
33 
34 //---------------------------------------------------------
35 // Pos
36 // depending on type _tick or _frame is a cached
37 // value. When the tempomap changes, all cached values
38 // are invalid. Sn is used to check for tempomap
39 // changes.
40 //---------------------------------------------------------
41 
42 class Pos {
44  bool _valid;
45  mutable int sn;
46  mutable unsigned _tick;
47  mutable unsigned _frame;
48 
49  protected:
52 
53  public:
54  Pos();
56  Pos(TempoMap*, TimeSigMap*, int measure, int beat, int tick);
57  Pos(TempoMap*, TimeSigMap*, int minute, int sec, int frame, int subframe);
58  Pos(TempoMap*, TimeSigMap*, unsigned, TType type = TType::TICKS);
59  Pos(TempoMap*, TimeSigMap*, const QString&);
60 
61  void setContext(TempoMap* t, TimeSigMap* s) { tempo = t; sig = s; }
62  void dump(int n = 0) const;
63 
64  unsigned time(TType t) const { return t == TType::TICKS ? tick() : frame(); }
65  void mbt(int* measure, int* beat, int* tick) const;
66  void msf(int* minute, int* sec, int* frame, int* subframe) const;
67  SigEvent timesig() const;
68  void snap(int);
69  void upSnap(int);
70  void downSnap(int);
71  Pos snapped(int) const;
72  Pos upSnapped(int) const;
73  Pos downSnapped(int) const;
74 
75  void invalidSn() { sn = -1; }
76 
77  TType type() const { return _type; }
78  void setType(TType t);
79 
80  Pos& operator+=(const Pos& a);
81  Pos& operator+=(int a);
82  Pos& operator-=(const Pos& a);
83  Pos& operator-=(int a);
84 
85  bool operator>=(const Pos& s) const;
86  bool operator>(const Pos& s) const;
87  bool operator<(const Pos& s) const;
88  bool operator<=(const Pos& s) const;
89  bool operator==(const Pos& s) const;
90  bool operator!=(const Pos& s) const;
91 
92  friend Pos operator+(const Pos& a, const Pos& b);
93  friend Pos operator-(const Pos& a, const Pos& b);
94  friend Pos operator+(const Pos& a, int b);
95  friend Pos operator-(const Pos& a, int b);
96 
97  unsigned tick() const;
98  unsigned frame() const;
99  void setTick(unsigned);
100  void setFrame(unsigned);
101 
102  void write(XmlWriter&, const char*) const;
103  void read(XmlReader&);
104  bool valid() const { return _valid && tempo && sig; }
105  void setInvalid() { _valid = false; }
106  };
107 
108 //---------------------------------------------------------
109 // PosLen
110 //---------------------------------------------------------
111 
112 class PosLen : public Pos {
113  mutable unsigned _lenTick;
114  mutable unsigned _lenFrame;
115  mutable int sn;
116 
117  public:
119  PosLen(const PosLen&);
120  void dump(int n = 0) const;
121 
122  void write(XmlWriter&, const char*) const;
123  void read(XmlReader&);
124  void setLenTick(unsigned);
125  void setLenFrame(unsigned);
126  unsigned lenTick() const;
127  unsigned lenFrame() const;
128  Pos end() const;
129  unsigned endTick() const { return end().tick(); }
130  unsigned endFrame() const { return end().frame(); }
131  void setPos(const Pos&);
132 
133  bool operator==(const PosLen& s) const;
134  };
135 
136 
137 } // namespace Ms
138 #endif
139 
unsigned _frame
Definition: pos.h:47
unsigned endFrame() const
Definition: pos.h:130
Definition: tempomap.h:22
Definition: xml.h:67
int sn
Definition: pos.h:45
unsigned _lenTick
Definition: pos.h:113
bool valid() const
Definition: pos.h:104
void setInvalid()
Definition: pos.h:105
TimeSigMap * sig
Definition: pos.h:51
TempoMap * tempo
Definition: pos.h:50
void setContext(TempoMap *t, TimeSigMap *s)
Definition: pos.h:61
unsigned endTick() const
Definition: pos.h:129
unsigned time(TType t) const
Definition: pos.h:64
TType _type
Definition: pos.h:43
bool _valid
Definition: pos.h:44
Definition: aeolus.cpp:26
Pos operator+(const Pos &a, int b)
Definition: pos.cpp:184
Definition: xml.h:218
void invalidSn()
Definition: pos.h:75
Definition: xmlwriter.h:26
int sn
Definition: pos.h:115
Definition: tempo.h:45
Pos operator-(const Pos &a, int b)
Definition: pos.cpp:190
unsigned _lenFrame
Definition: pos.h:114
Definition: xmlreader.h:28
Definition: sig.h:97
unsigned _tick
Definition: pos.h:46
TType
Definition: pos.h:32
Definition: sig.h:127
TType type() const
Definition: pos.h:77
Definition: pos.h:112
Definition: pos.h:42