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
|
//=============================================================================
// MusE
// Linux Music Editor
// $Id: tempo.h 2135 2009-09-28 16:05:57Z wschweer $
//
// Copyright (C) 2002-2009 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 __AL_TEMPO_H__
#define __AL_TEMPO_H__
namespace AL {
class Xml;
//---------------------------------------------------------
// Tempo Event
//---------------------------------------------------------
struct TEvent {
double tempo; // beats per second
double time; // precomputed time for tick in sec
int read(QDomElement);
void write(Xml&, int) const;
TEvent() {
tempo = 0.0;
}
TEvent(const TEvent& e) {
tempo = e.tempo;
time = e.time;
}
TEvent(double t) {
tempo = t;
time = 0.0;
}
bool valid() const { return tempo != 0.0; }
};
//---------------------------------------------------------
// Tempomap
//---------------------------------------------------------
typedef std::map<int, TEvent>::iterator iTEvent;
typedef std::map<int, TEvent>::const_iterator ciTEvent;
typedef std::map<int, TEvent>::reverse_iterator riTEvent;
typedef std::map<int, TEvent>::const_reverse_iterator criTEvent;
class TempoMap : public std::map<int, TEvent> {
int _tempoSN; // serial no to track tempo changes
bool useList;
double _tempo; // tempo if not using tempo list (beats per second)
int _relTempo; // rel. tempo (100 == 1.0)
void normalize();
void add(int tick, double tempo);
void change(int tick, double newTempo);
void del(iTEvent);
void del(int tick);
void add(int t, const TEvent&);
public:
TempoMap();
void clear();
void read(QDomElement, int sourceDivision);
void write(Xml&) const;
void dump() const;
double tempo(int tick) const;
double tick2time(int tick, int* sn = 0) const;
double tick2timeLC(int tick, int* sn) const;
double tick2time(int tick, double time, int* sn) const;
int time2tick(double time, int* sn = 0) const;
int time2tick(double time, int tick, int* sn) const;
int tempoSN() const { return _tempoSN; }
void setTempo(int tick, double newTempo);
void addTempo(int t, double tempo);
void addTempo(int tick, const TEvent& ev);
void delTempo(int tick);
void changeTempo(int tick, double newTempo);
bool setMasterFlag(int tick, bool val);
int tick2samples(int tick);
int samples2tick(int samples);
void setRelTempo(int val);
int relTempo() const { return _relTempo; }
void removeTime(int start, int len);
void insertTime(int start, int len);
TEvent getTempo(int tick) const;
};
} // namespace AL
#endif
|