~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to tempo.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//  $Id: tempo.h,v 1.2 2001/11/20 15:19:32 muse Exp $
 
5
//
 
6
//  (C) Copyright 1999/2000 Werner Schweer (ws@seh.de)
 
7
//=========================================================
 
8
 
 
9
#ifndef __TEMPO_H__
 
10
#define __TEMPO_H__
 
11
 
 
12
#include <map>
 
13
 
 
14
#ifndef MAX_TICK
 
15
#define MAX_TICK (0x7fffffff/100)
 
16
#endif
 
17
 
 
18
class Xml;
 
19
 
 
20
//---------------------------------------------------------
 
21
//   Tempo Event
 
22
//---------------------------------------------------------
 
23
 
 
24
struct TEvent {
 
25
      int tempo;
 
26
      int tick;            // new tempo at tick
 
27
      double time;         // precomputed time for tick in sec
 
28
 
 
29
      int read(Xml&);
 
30
      void write(int, Xml&, int) const;
 
31
 
 
32
      TEvent() { }
 
33
      TEvent(int t, int tk) {
 
34
            tempo = t;
 
35
            tick = tk;
 
36
            time = 0.0;
 
37
            }
 
38
      };
 
39
 
 
40
//---------------------------------------------------------
 
41
//   TempoList
 
42
//---------------------------------------------------------
 
43
 
 
44
typedef std::map<int, TEvent*, std::less<int> >::iterator iTEvent;
 
45
typedef std::map<int, TEvent*, std::less<int> >::const_iterator ciTEvent;
 
46
typedef std::map<int, TEvent*, std::less<int> >::reverse_iterator riTEvent;
 
47
typedef std::map<int, TEvent*, std::less<int> >::const_reverse_iterator criTEvent;
 
48
 
 
49
class TempoList : public std::map<int, TEvent*, std::less<int> > {
 
50
      int _tempoSN;           // serial no to track tempo changes
 
51
      bool useList;
 
52
      int _tempo;             // tempo if not using tempo list
 
53
 
 
54
      void normalize();
 
55
      void add(int tick, int tempo);
 
56
      void change(int tick, int newTempo);
 
57
      void del(iTEvent);
 
58
      void del(int tick);
 
59
 
 
60
   public:
 
61
      TempoList();
 
62
      void clear();
 
63
 
 
64
      void read(Xml&);
 
65
      void write(int, Xml&) const;
 
66
      void dump() const;
 
67
 
 
68
      int tempo(int tick) const;
 
69
      double tick2time(int tick, int* sn = 0) const;
 
70
      double tick2timeLC(int tick, int* sn) const;
 
71
      double tick2time(int tick, double time, int* sn) const;
 
72
      int time2tick(double time, int* sn = 0) const;
 
73
      int time2tick(double time, int tick, int* sn) const;
 
74
      int tempoSN() const { return _tempoSN; }
 
75
      void setTempo(int tick, int newTempo);
 
76
      void addTempo(int t, int tempo);
 
77
      void delTempo(int tick);
 
78
      void changeTempo(int tick, int newTempo);
 
79
      bool setMasterFlag(int tick, bool val);
 
80
 
 
81
      int tick2samples(int tick);
 
82
      int samples2tick(int samples);
 
83
      };
 
84
 
 
85
extern TempoList tempomap;
 
86
#endif