MuseScore  3.4
Music composition and notation
tempo.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 Werner Schweer
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 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __AL_TEMPO_H__
14 #define __AL_TEMPO_H__
15 
16 namespace Ms {
17 
18 class XmlWriter;
19 
20 enum class TempoType : char { INVALID = 0x0, PAUSE = 0x1, FIX = 0x2, RAMP = 0x4};
21 
22 typedef QFlags<TempoType> TempoTypes;
24 
25 //---------------------------------------------------------
26 // Tempo Event
27 //---------------------------------------------------------
28 
29 struct TEvent {
30  TempoTypes type;
31  qreal tempo; // beats per second
32  qreal pause; // pause in seconds
33  qreal time; // precomputed time for tick in sec
34 
35  TEvent();
36  TEvent(const TEvent& e);
37  TEvent(qreal bps, qreal seconds, TempoType t);
38  bool valid() const;
39  };
40 
41 //---------------------------------------------------------
42 // Tempomap
43 //---------------------------------------------------------
44 
45 class TempoMap : public std::map<int, TEvent> {
46  int _tempoSN; // serial no to track tempo changes
47  qreal _tempo; // tempo if not using tempo list (beats per second)
48  qreal _relTempo; // rel. tempo
49 
50  void normalize();
51  void del(int tick);
52 
53  public:
54  TempoMap();
55  void clear();
56  void clearRange(int tick1, int tick2);
57 
58  void dump() const;
59 
60  qreal tempo(int tick) const;
61 
62  qreal tick2time(int tick, int* sn = 0) const;
63  qreal tick2timeLC(int tick, int* sn) const;
64  qreal tick2time(int tick, qreal time, int* sn) const;
65  int time2tick(qreal time, int* sn = 0) const;
66  int time2tick(qreal time, int tick, int* sn) const;
67  int tempoSN() const { return _tempoSN; }
68 
69  void setTempo(int t, qreal);
70  void setPause(int t, qreal);
71  void delTempo(int tick);
72 
73  void setRelTempo(qreal val);
74  qreal relTempo() const { return _relTempo; }
75  };
76 
77 } // namespace Ms
78 #endif
qreal relTempo() const
Definition: tempo.h:74
QFlags< TempoType > TempoTypes
Definition: tempo.h:22
qreal _relTempo
Definition: tempo.h:48
qreal _tempo
Definition: tempo.h:47
qreal time
Definition: tempo.h:33
int tempoSN() const
Definition: tempo.h:67
int _tempoSN
Definition: tempo.h:46
TempoTypes type
Definition: tempo.h:30
Definition: aeolus.cpp:26
qreal pause
Definition: tempo.h:32
Definition: xmlwriter.h:26
Definition: tempo.h:29
qreal tempo
Definition: tempo.h:31
Definition: tempo.h:45
TempoType
Definition: tempo.h:20
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementFlags)