File: sig.h

package info (click to toggle)
musescore 1.3%2Bdfsg1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 148,004 kB
  • ctags: 30,854
  • sloc: cpp: 372,716; xml: 148,276; ansic: 6,156; python: 2,202; perl: 710; sh: 505; makefile: 227
file content (105 lines) | stat: -rw-r--r-- 3,826 bytes parent folder | download | duplicates (2)
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
//=============================================================================
//  MusE Score
//  Linux Music Score Editor
//  $Id: sig.h 3482 2010-09-21 07:10:03Z lasconic $
//
//  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_SIG_H__
#define __AL_SIG_H__

#include "fraction.h"

namespace AL {
class Xml;

//-------------------------------------------------------------------
//   Time Signature Event
//    Incomplete measures as for example pickup measures have
//    a nominal duration different from actual duration.
//-------------------------------------------------------------------

struct SigEvent {
      Fraction actual;
      Fraction nominal;
      int bar;                ///< precomputed value
      int ticks;              ///< ticks per measure, precomputed value

      int read(QDomElement, int fileDivision);
      void write(Xml&, int) const;

      SigEvent() : actual(0, 0) {}                    ///< default SigEvent is invalid
      SigEvent(const Fraction&);                      ///< set regular event
      SigEvent(const Fraction&, const Fraction&);     ///< set irregular event

      bool operator==(const SigEvent& e) const;
      bool valid() const { return actual.isValid(); }
      QString print() const {
            return valid() ? actual.print() : QString("void");
            }
      bool nominalEqual(const SigEvent& e) const {
            return nominal.identical(e.nominal);
            }
      bool nominalEqualActual() const { return actual.identical(nominal); }
      Fraction fraction() const       { return actual;            }
      Fraction getNominal() const     { return nominal;           }
      };

//---------------------------------------------------------
//   SigList
//---------------------------------------------------------

typedef std::map<const int, SigEvent>::iterator iSigEvent;
typedef std::map<const int, SigEvent>::const_iterator ciSigEvent;

class TimeSigMap : public std::map<const int, SigEvent > {
      unsigned _serial;
      void normalize();

   public:
      TimeSigMap();
      void add(int tick, const Fraction&);
      void add(int tick, const Fraction& a, const Fraction& n);
      void add(int tick, int ticks, const Fraction& nominal);
      void add(int tick, const SigEvent& ev);

      void del(int tick);

      void read(QDomElement, int fileDiv);
      void write(Xml&) const;
      void dump() const;

      const SigEvent& timesig(int tick) const;

      void tickValues(int t, int* bar, int* beat, int* tick) const;
      int bar2tick(int bar, int beat, int tick) const;

      int ticksMeasure(int tick) const;

      void removeTime(int start, int len);
      void insertTime(int start, int len);
      int serial() const { return _serial; }
      unsigned raster(unsigned tick, int raster) const;
      unsigned raster1(unsigned tick, int raster) const;    // round down
      unsigned raster2(unsigned tick, int raster) const;    // round up
      int rasterStep(unsigned tick, int raster) const;
      Fraction measureRest(unsigned tick) const;
      };

extern int ticks_measure(const Fraction&);

}     // namespace AL
#endif