MuseScore  3.4
Music composition and notation
spatium.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 __SPATIUM_H__
14 #define __SPATIUM_H__
15 
16 namespace Ms {
17 
18 //---------------------------------------------------------
19 // Spatium
20 // - a unit of measure
21 // - the distance between two note lines
22 // - used for many layout items
23 //---------------------------------------------------------
24 
25 class Spatium {
26  qreal _val;
27 
28  public:
29  constexpr Spatium() : _val(0.0) {}
30  explicit Spatium(qreal v) { _val = v; }
31 
32  constexpr qreal val() const { return _val; }
33 
34  bool operator>(const Spatium& a) const { return _val > a._val; }
35  bool operator<(const Spatium& a) const { return _val < a._val; }
36  bool operator==(const Spatium& a) const { return _val == a._val; }
37  bool operator!=(const Spatium& a) const { return _val != a._val; }
38  bool isZero() const { return _val == 0.0; }
39 
40  Spatium& operator+=(const Spatium& a) {
41  _val += a._val;
42  return *this;
43  }
44  Spatium& operator-=(const Spatium& a) {
45  _val -= a._val;
46  return *this;
47  }
48  Spatium& operator/=(qreal d) {
49  _val /= d;
50  return *this;
51  }
52  qreal operator/(const Spatium& b) {
53  return _val / b._val;
54  }
55  Spatium& operator*=(int d) {
56  _val *= d;
57  return *this;
58  }
59  Spatium& operator*=(qreal d) {
60  _val *= d;
61  return *this;
62  }
63  Spatium operator-() const { return Spatium(-_val); }
64  operator QVariant() const { return QVariant::fromValue(*this); }
65 
66  static double toDouble(const Spatium& v) { return v._val; }
67  };
68 
69 inline Spatium operator+(const Spatium& a, const Spatium& b)
70  {
71  Spatium r(a);
72  r += b;
73  return r;
74  }
75 inline Spatium operator-(const Spatium& a, const Spatium& b)
76  {
77  Spatium r(a);
78  r -= b;
79  return r;
80  }
81 inline Spatium operator/(const Spatium& a, qreal b)
82  {
83  Spatium r(a);
84  r /= b;
85  return r;
86  }
87 inline Spatium operator*(const Spatium& a, int b)
88  {
89  Spatium r(a);
90  r *= b;
91  return r;
92  }
93 inline Spatium operator*(int a, const Spatium& b)
94  {
95  Spatium r(b);
96  r *= a;
97  return r;
98  }
99 inline Spatium operator*(const Spatium& a, qreal b)
100  {
101  Spatium r(a);
102  r *= b;
103  return r;
104  }
105 inline Spatium operator*(qreal a, const Spatium& b)
106  {
107  Spatium r(b);
108  r *= a;
109  return r;
110  }
111 } // namespace Ms
112 
113 Q_DECLARE_METATYPE(Ms::Spatium);
114 
115 #endif
116 
Spatium & operator-=(const Spatium &a)
Definition: spatium.h:44
bool isZero() const
Definition: spatium.h:38
constexpr Spatium()
Definition: spatium.h:29
qreal _val
Definition: spatium.h:26
static double toDouble(const Spatium &v)
Definition: spatium.h:66
Fraction operator*(const Fraction &f, int v)
Definition: fraction.h:252
Spatium & operator*=(qreal d)
Definition: spatium.h:59
Spatium(qreal v)
Definition: spatium.h:30
constexpr qreal val() const
Definition: spatium.h:32
bool operator>(const Spatium &a) const
Definition: spatium.h:34
Definition: aeolus.cpp:26
Definition: spatium.h:25
Pos operator+(const Pos &a, int b)
Definition: pos.cpp:184
Spatium & operator+=(const Spatium &a)
Definition: spatium.h:40
qreal operator/(const Spatium &b)
Definition: spatium.h:52
Spatium & operator*=(int d)
Definition: spatium.h:55
Spatium & operator/=(qreal d)
Definition: spatium.h:48
Spatium operator-() const
Definition: spatium.h:63
bool operator!=(const Spatium &a) const
Definition: spatium.h:37
bool operator==(const Spatium &a) const
Definition: spatium.h:36
bool operator<(const Spatium &a) const
Definition: spatium.h:35