- Main Page
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Members

# Rhythm Class Reference

Rhythm class implements standard methods and data structures to manipulate musical rhythm arithmetically. More...

`#include <Rhythm.h>`

List of all members.

## Public Member Functions
| Rhythm ()
| Default constructor.
| Rhythm (Integer i)
| Default constructor.
| Rhythm (Real x)
| Construct rhythm given a fractional rhythmic value.
| Rhythm (Integer num, Integer den)
| Construct rhythm given a rational fraction rhythmic value.
| Rhythm (Real x, Integer &num, Integer &den)
| Construct rhythm given a Real fractional rhythmic value, determine its rational approximation, assign numerator and denominator to reference arguments.
| Rhythm (Rhythm x, Integer &num, Integer &den)
| Construct rhythm given a Rhythm, determine its rational approximation, assign numerator and denominator to reference arguments.
Bool | operator== (Const Rhythm &x) Const
| Rhythm equality operator.
Bool | operator!= (Const Rhythm &x) Const
| Rhythm inequality operator.
Bool | operator>= (Const Rhythm &x) Const
| Rhythm >= operator.
Bool | operator> (Const Rhythm &x) Const
| Rhythm > operator.
Bool | operator< (Const Rhythm &x) Const
| Rhythm < operator.
Bool | operator<= (Const Rhythm &x) Const
| Rhythm <= operator.
Rhythm & | operator+= (Const Real x)
| Rhythm plus-equals operator.
Rhythm & | operator+= (Rhythm x)
| Rhythm plus-equals operator.
Rhythm & | operator-= (Const Real x)
| Rhythm minus-equals operator.
Rhythm & | operator-= (Rhythm x)
| Rhythm minus-equals operator.
Rhythm & | operator *= (Const Real x)
| Rhythm times-equals operator.
Rhythm & | operator *= (Rhythm x)
| Rhythm times-equals operator.
Rhythm & | operator/= (Const Real x)
| Rhythm divide-equals operator.
Rhythm & | operator/= (Rhythm x)
| Rhythm divide-equals operator.
Rhythm | operator+ (Rhythm &x)
| Rhythm addition operator.
Rhythm | operator- (Rhythm &x)
| Rhythm subtraction operator.
Rhythm | operator * (Rhythm &x)
| Rhythm times operator.
Rhythm | operator/ (Rhythm &x)
| Rhythm divide operator.
Rhythm | operator+ (Const Real x)
| Rhythm add to Real operator.
Rhythm | operator- (Const Real x)
| Rhythm subtract from Real operator.
Rhythm | operator * (Const Real x)
| Rhythm multiply by Real operator.
Rhythm | operator/ (Const Real x)
| Rhythm divide by Real operator.
String | print (String s=0) Const
| Print Rhythm prefixed by String.
Static Real | tempo (Void)
| Return the tempo used by all Rhythm instances to determine tempo.
Static Real | tempo (Real t)
| Set the tempo used by all Rhythm instances to determine tempo.
Real | mm (Rhythm beats, Real perMinute) Const
| Return the duration of a Rhythm given a Real beats per minute.
Real | duration ()
| Return the duration of this Rhythm at the prevailing tempo.
Real | absDuration () Const
| Return the absolute duration of this Rhythm.
## Friends
ostream & | operator<< (ostream &, Rhythm &)
istream & | operator>> (istream &is, Rhythm &p)
Bool | operator== (Integer &i, Rhythm &p)
Bool | operator== (Rhythm &p, Integer &i)
Bool | operator!= (Integer &i, Rhythm &p)
Bool | operator!= (Rhythm &p, Integer &i)
Bool | operator>= (Rhythm &p, Integer &r)
Bool | operator>= (Integer &i, Rhythm &p)
Bool | operator> (Rhythm &p, Integer &i)
Bool | operator> (Integer &i, Rhythm &p)
Bool | operator<= (Rhythm &p, Integer &i)
Bool | operator<= (Integer &i, Rhythm &p)
Bool | operator== (Real &r, Rhythm &p)
Bool | operator== (Rhythm &p, Real &r)
Bool | operator!= (Real &r, Rhythm &p)
Bool | operator!= (Rhythm &p, Real &r)
Bool | operator>= (Rhythm &p, Real &r)
Bool | operator>= (Real &r, Rhythm &p)
Bool | operator> (Rhythm &p, Real &r)
Bool | operator> (Real &r, Rhythm &p)
Bool | operator<= (Rhythm &p, Real &r)
Bool | operator<= (Real &r, Rhythm &p)

## Detailed Description

Rhythm class implements standard methods and data structures to manipulate musical rhythm arithmetically.

Definition at line 26 of file Rhythm.h.

## Constructor & Destructor Documentation

Rhythm::Rhythm | ( |  | ) | `[inline]`

Default constructor.

Definition at line 57 of file Rhythm.h.

Referenced by operator *(), operator+(), operator+=(), operator-(), and operator/().

    00057 : m_num(0), m_den(0) { }

Rhythm::Rhythm | ( | Integer | i | ) | `[inline]`

Default constructor.

Definition at line 60 of file Rhythm.h.

    00060 : m_num(i), m_den(i) { }

Rhythm::Rhythm | ( | Real | x | ) | `[inline]`

Construct rhythm given a fractional rhythmic value.

Parameters:

  | x | Rhythmic fraction expressed as a Real

Definition at line 64 of file Rhythm.h.

References RealToRational().

    00064 : m_num(0), m_den(0) { RealToRational( x, m_num, m_den ); }

Rhythm::Rhythm | ( | Integer | num,
|  | Integer | den |
| ) |  |  | `[inline]`

Construct rhythm given a rational fraction rhythmic value.

Parameters:

  | num | Numerator of rational fraction
  | den | Denominator of rational fraction

Definition at line 69 of file Rhythm.h.

References If.

    00069                                          : m_num(num), m_den(den) {
    00070                 If (m_den == 0)
    00071                         m_den = 1;
    00072         }

Rhythm::Rhythm | ( | Real | x,
|  | Integer & | num,
|  | Integer & | den |
| ) |  |  | `[inline]`

Construct rhythm given a Real fractional rhythmic value, determine its rational approximation, assign numerator and denominator to reference arguments.

Parameters:

  | x | Real fractional reference rhythmic value
  | num | Reference Integer numerator of derived rational fraction approximation
  | den | Reference Integer denominator of derived rational fraction approximation

Definition at line 78 of file Rhythm.h.

References RealToRational().

    00078                                                    : m_num(0), m_den(0) {
    00079                 RealToRational( x, num, den );
    00080                 m_num = num;
    00081                 m_den = den;
    00082         }

Rhythm::Rhythm | ( | Rhythm | x,
|  | Integer & | num,
|  | Integer & | den |
| ) |  |  | `[inline]`

Construct rhythm given a Rhythm, determine its rational approximation, assign numerator and denominator to reference arguments.

Parameters:

  | x | Rhythmic value
  | num | Reference Integer numerator of derived rational fraction approximation
  | den | Reference Integer denominator of derived rational fraction approximation

Definition at line 88 of file Rhythm.h.

References quotient(), and RealToRational().

    00088                                                      : m_num(0), m_den(0) {
    00089                 RealToRational( x.quotient(), num, den );
    00090                 m_num = num;
    00091                 m_den = den;
    00092         }

## Member Function Documentation

Real Rhythm::absDuration | ( |  | ) | `[inline]`

Return the absolute duration of this Rhythm.

Definition at line 240 of file Rhythm.h.

References Return.

Referenced by AbsDuration(), and Duration().

    00240                                   {
    00241                 Return ( Real(m_num) / Real(m_den) );
    00242         }

Real Rhythm::duration | ( |  | ) | `[inline]`

Return the duration of this Rhythm at the prevailing tempo.

Definition at line 235 of file Rhythm.h.

References Return.

Referenced by Duration().

    00235                          {
    00236                 Return ( quotient() * s_fourQuarters );
    00237         }

Real Rhythm::mm | ( | Rhythm | beats,
|  | Real | perMinute |
| ) |  |  | `[inline]`

Return the duration of a Rhythm given a Real beats per minute.

Parameters:

  | beats | Rhythm indicating a duration to measure in time
  | perMinute | Real value indicating how many beats occupy a minute

Returns:
  Corresponding duration of rhythmic value in seconds

Definition at line 230 of file Rhythm.h.

References Return.

    00230                                                       {
    00231                 Return( 1.0 / (4.0 * beats.quotient()) * 60.0 / perMinute );
    00232         }

Rhythm Rhythm::operator * | ( | Const Real | x | ) | `[inline]`

Rhythm multiply by Real operator.

Definition at line 195 of file Rhythm.h.

References Return, and Rhythm().

    00195                                        {
    00196                 Return( Rhythm(quotient() * x) );
    00197         }

Rhythm Rhythm::operator * | ( | Rhythm & | x | ) | `[inline]`

Rhythm times operator.

Definition at line 175 of file Rhythm.h.

References quotient(), Return, and Rhythm().

    00175                                     {
    00176                 Return( Rhythm(quotient() * x.quotient()) );
    00177         }

Rhythm& Rhythm::operator *= | ( | Rhythm | x | ) | `[inline]`

Rhythm times-equals operator.

Definition at line 150 of file Rhythm.h.

References quotient(), and Return.

    00150                                      {
    00151                 Return( *this = quotient() * x.quotient() );
    00152         }

Rhythm& Rhythm::operator *= | ( | Const Real | x | ) | `[inline]`

Rhythm times-equals operator.

Definition at line 145 of file Rhythm.h.

References Return.

    00145                                          {
    00146                 Return( *this = quotient() * x );
    00147         }

Bool Rhythm::operator!= | ( | Const Rhythm & | x | ) | `[inline]`

Rhythm inequality operator.

Definition at line 100 of file Rhythm.h.

References Return.

    00100                                                {
    00101                 Return m_num != x.m_num || m_den != x.m_den;
    00102         }

Rhythm Rhythm::operator+ | ( | Const Real | x | ) | `[inline]`

Rhythm add to Real operator.

Definition at line 185 of file Rhythm.h.

References Return, and Rhythm().

    00185                                        {
    00186                 Return( Rhythm(quotient() + x) );
    00187         }

Rhythm Rhythm::operator+ | ( | Rhythm & | x | ) | `[inline]`

Rhythm addition operator.

Definition at line 165 of file Rhythm.h.

References quotient(), Return, and Rhythm().

    00165                                     {
    00166                 Return( Rhythm(quotient() + x.quotient()) );
    00167         }

Rhythm& Rhythm::operator+= | ( | Rhythm | x | ) | `[inline]`

Rhythm plus-equals operator.

Definition at line 130 of file Rhythm.h.

References quotient(), Return, and Rhythm().

    00130                                      {
    00131                 Return( *this = Rhythm(quotient() + x.quotient()) );
    00132         }

Rhythm& Rhythm::operator+= | ( | Const Real | x | ) | `[inline]`

Rhythm plus-equals operator.

Definition at line 125 of file Rhythm.h.

References Return, and Rhythm().

    00125                                          {
    00126                 Return( *this = Rhythm(quotient() + x) );
    00127         }

Rhythm Rhythm::operator- | ( | Const Real | x | ) | `[inline]`

Rhythm subtract from Real operator.

Definition at line 190 of file Rhythm.h.

References Return, and Rhythm().

    00190                                        {
    00191                 Return( Rhythm(quotient() - x) );
    00192         }

Rhythm Rhythm::operator- | ( | Rhythm & | x | ) | `[inline]`

Rhythm subtraction operator.

Definition at line 170 of file Rhythm.h.

References quotient(), Return, and Rhythm().

    00170                                     {
    00171                 Return( Rhythm(quotient() - x.quotient()) );
    00172         }

Rhythm& Rhythm::operator-= | ( | Rhythm | x | ) | `[inline]`

Rhythm minus-equals operator.

Definition at line 140 of file Rhythm.h.

References quotient(), and Return.

    00140                                      {
    00141                 Return( *this = quotient() - x.quotient() );
    00142         }

Rhythm& Rhythm::operator-= | ( | Const Real | x | ) | `[inline]`

Rhythm minus-equals operator.

Definition at line 135 of file Rhythm.h.

References Return.

    00135                                          {
    00136                 Return( *this = quotient() - x );
    00137         }

Rhythm Rhythm::operator/ | ( | Const Real | x | ) | `[inline]`

Rhythm divide by Real operator.

Definition at line 200 of file Rhythm.h.

References Return, and Rhythm().

    00200                                        {
    00201                 Return( Rhythm(quotient() / x ) );
    00202         }

Rhythm Rhythm::operator/ | ( | Rhythm & | x | ) | `[inline]`

Rhythm divide operator.

Definition at line 180 of file Rhythm.h.

References quotient(), Return, and Rhythm().

    00180                                     {
    00181                 Return( Rhythm(quotient() / x.quotient()) );
    00182         }

Rhythm& Rhythm::operator/= | ( | Rhythm | x | ) | `[inline]`

Rhythm divide-equals operator.

Definition at line 160 of file Rhythm.h.

References quotient(), and Return.

    00160                                      {
    00161                 Return( *this = quotient() / x.quotient() );
    00162         }

Rhythm& Rhythm::operator/= | ( | Const Real | x | ) | `[inline]`

Rhythm divide-equals operator.

Definition at line 155 of file Rhythm.h.

References Return.

    00155                                          {
    00156                 Return( *this = quotient() / x );
    00157         }

Bool Rhythm::operator< | ( | Const Rhythm & | x | ) | `[inline]`

Rhythm < operator.

Definition at line 115 of file Rhythm.h.

References Return.

    00115                                               {
    00116                 Return quotient() < x.quotient();
    00117         }

Bool Rhythm::operator<= | ( | Const Rhythm & | x | ) | `[inline]`

Rhythm <= operator.

Definition at line 120 of file Rhythm.h.

References Return.

    00120                                                {
    00121                 Return quotient() <= x.quotient();
    00122         }

Bool Rhythm::operator== | ( | Const Rhythm & | x | ) | `[inline]`

Rhythm equality operator.

Definition at line 95 of file Rhythm.h.

References And, and Return.

    00095                                                {
    00096                 Return m_num == x.m_num  And m_den == x.m_den;
    00097         }

Bool Rhythm::operator> | ( | Const Rhythm & | x | ) | `[inline]`

Rhythm > operator.

Definition at line 110 of file Rhythm.h.

References Return.

    00110                                               {
    00111                 Return quotient() > x.quotient();
    00112         }

Bool Rhythm::operator>= | ( | Const Rhythm & | x | ) | `[inline]`

Rhythm >= operator.

Definition at line 105 of file Rhythm.h.

References Return.

    00105                                                {
    00106                 Return quotient() >= x.quotient();
    00107         }

String Rhythm::print | ( | String | s = `0` | ) | `[inline]`

Print Rhythm prefixed by String.

Parameters:

  | s | Prefix string

Definition at line 206 of file Rhythm.h.

References If, and Return.

Referenced by operator<<().

    00206                                          {
    00207                 If (s)
    00208                         cout << s;
    00209                 sprintf(s_buf, "{%d,%d}", m_num, m_den);
    00210                 Return s_buf;
    00211         }

Static Real Rhythm::tempo | ( | Real | t | ) | `[inline]`

Set the tempo used by all Rhythm instances to determine tempo.

Returns:
  Current tempo

Definition at line 220 of file Rhythm.h.

References Return.

    00220                                   {
    00221                 Real s = s_tempo;
    00222                 s_tempo = t;
    00223                 Return s;
    00224         }

Static Real Rhythm::tempo | ( | Void |  | ) | `[inline]`

Return the tempo used by all Rhythm instances to determine tempo.

Definition at line 214 of file Rhythm.h.

References Return.

Referenced by SetTempoScale().

    00214                                 {
    00215                 Return s_tempo;
    00216         }

## Friends And Related Function Documentation

Bool operator!= | ( | Rhythm & | p,
|  | Real & | r |
| ) |  |  | `[friend]`

Definition at line 45 of file Rhythm.h.

    00045 { Return p.quotient() != r; }

Bool operator!= | ( | Real & | r,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 44 of file Rhythm.h.

    00044 { Return r != p.quotient(); }

Bool operator!= | ( | Rhythm & | p,
|  | Integer & | i |
| ) |  |  | `[friend]`

Definition at line 34 of file Rhythm.h.

    00034 { Return p.quotient() != i; }

Bool operator!= | ( | Integer & | i,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 33 of file Rhythm.h.

    00033 { Return i != p.quotient(); }

ostream& operator<< | ( | ostream & | os,
|  | Rhythm & | r |
| ) |  |  | `[friend]`

Definition at line 65 of file Rhythm.cpp.

    00066 {
    00067         os << r.print();
    00068         Return os;
    00069 }

Bool operator<= | ( | Real & | r,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 51 of file Rhythm.h.

    00051 { Return r <= p.quotient(); }

Bool operator<= | ( | Rhythm & | p,
|  | Real & | r |
| ) |  |  | `[friend]`

Definition at line 50 of file Rhythm.h.

    00050 { Return p.quotient() <= r; }

Bool operator<= | ( | Integer & | i,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 40 of file Rhythm.h.

    00040 { Return i <= p.quotient(); }

Bool operator<= | ( | Rhythm & | p,
|  | Integer & | i |
| ) |  |  | `[friend]`

Definition at line 39 of file Rhythm.h.

    00039 { Return p.quotient() <= i; }

Bool operator== | ( | Rhythm & | p,
|  | Real & | r |
| ) |  |  | `[friend]`

Definition at line 43 of file Rhythm.h.

    00043 { Return p.quotient() == r; }

Bool operator== | ( | Real & | r,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 42 of file Rhythm.h.

    00042 { Return r == p.quotient(); }

Bool operator== | ( | Rhythm & | p,
|  | Integer & | i |
| ) |  |  | `[friend]`

Definition at line 32 of file Rhythm.h.

    00032 { Return p.quotient() == i; }

Bool operator== | ( | Integer & | i,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 31 of file Rhythm.h.

    00031 { Return i == p.quotient(); }

Bool operator> | ( | Real & | r,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 49 of file Rhythm.h.

    00049 { Return r > p.quotient(); }

Bool operator> | ( | Rhythm & | p,
|  | Real & | r |
| ) |  |  | `[friend]`

Definition at line 48 of file Rhythm.h.

    00048 { Return p.quotient() > r; }

Bool operator> | ( | Integer & | i,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 38 of file Rhythm.h.

    00038 { Return i > p.quotient(); }

Bool operator> | ( | Rhythm & | p,
|  | Integer & | i |
| ) |  |  | `[friend]`

Definition at line 37 of file Rhythm.h.

    00037 { Return p.quotient() > i; }

Bool operator>= | ( | Real & | r,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 47 of file Rhythm.h.

    00047 { Return r >= p.quotient(); }

Bool operator>= | ( | Rhythm & | p,
|  | Real & | r |
| ) |  |  | `[friend]`

Definition at line 46 of file Rhythm.h.

    00046 { Return p.quotient() >= r; }

Bool operator>= | ( | Integer & | i,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 36 of file Rhythm.h.

    00036 { Return i >= p.quotient(); }

Bool operator>= | ( | Rhythm & | p,
|  | Integer & | r |
| ) |  |  | `[friend]`

Definition at line 35 of file Rhythm.h.

    00035 { Return p.quotient() >= r; }

istream& operator>> | ( | istream & | is,
|  | Rhythm & | p |
| ) |  |  | `[friend]`

Definition at line 71 of file Rhythm.cpp.

    00072 {
    00073         char ch;
    00074         is >> ch && (ch == '{' || ch == '(')
    00075                 && is >> p.m_num >> ch && ch == ','
    00076                 && is >> p.m_den >> ch && (ch == '}' || ch == '(');
    00077         Return is;
    00078 }

The documentation for this class was generated from the following files:

- C:/Musimathics_local/Musimat/include/Rhythm.h
- C:/Musimathics_local/Musimat/MusimatLib/Rhythm.cpp