Public Member Functions | Friends

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.
Rhythmoperator+= (Const Real x)
 Rhythm plus-equals operator.
Rhythmoperator+= (Rhythm x)
 Rhythm plus-equals operator.
Rhythmoperator-= (Const Real x)
 Rhythm minus-equals operator.
Rhythmoperator-= (Rhythm x)
 Rhythm minus-equals operator.
Rhythmoperator*= (Const Real x)
 Rhythm times-equals operator.
Rhythmoperator*= (Rhythm x)
 Rhythm times-equals operator.
Rhythmoperator/= (Const Real x)
 Rhythm divide-equals operator.
Rhythmoperator/= (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 29 of file Rhythm.h.


Constructor & Destructor Documentation

Rhythm::Rhythm (  ) [inline]

Default constructor.

Definition at line 60 of file Rhythm.h.

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

: m_num(0), m_den(0) { }
Rhythm::Rhythm ( Integer  i ) [inline]

Default constructor.

Definition at line 63 of file Rhythm.h.

: m_num(i), m_den(i) { }
Rhythm::Rhythm ( Real  x ) [inline]

Construct rhythm given a fractional rhythmic value.

Parameters:
xRhythmic fraction expressed as a Real

Definition at line 67 of file Rhythm.h.

References RealToRational().

: 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:
numNumerator of rational fraction
denDenominator of rational fraction

Definition at line 72 of file Rhythm.h.

References If.

                                         : m_num(num), m_den(den) { 
                If (m_den == 0)
                        m_den = 1;
        }
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:
xReal fractional reference rhythmic value
numReference Integer numerator of derived rational fraction approximation
denReference Integer denominator of derived rational fraction approximation

Definition at line 81 of file Rhythm.h.

References RealToRational().

                                                   : m_num(0), m_den(0) { 
                RealToRational( x, num, den ); 
                m_num = num;
                m_den = den;
        }
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:
xRhythmic value
numReference Integer numerator of derived rational fraction approximation
denReference Integer denominator of derived rational fraction approximation

Definition at line 91 of file Rhythm.h.

References RealToRational().

                                                     : m_num(0), m_den(0) { 
                RealToRational( x.quotient(), num, den ); 
                m_num = num;
                m_den = den;
        }

Member Function Documentation

Real Rhythm::absDuration (  ) [inline]

Return the absolute duration of this Rhythm.

Definition at line 252 of file Rhythm.h.

References Return.

Referenced by AbsDuration(), Duration(), and metronome().

                                  { 
                Return ( Real(m_num) / Real(m_den) );
        }
Real Rhythm::duration (  ) [inline]

Return the duration of this Rhythm at the prevailing tempo.

Definition at line 247 of file Rhythm.h.

References Return.

Referenced by Duration().

                         { 
                Return ( quotient() * s_fourQuarters );
        }
Real Rhythm::mm ( Rhythm  beats,
Real  perMinute 
) [inline]

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

Parameters:
beatsRhythm indicating a duration to measure in time
perMinuteReal value indicating how many beats occupy a minute
Returns:
Corresponding duration of rhythmic value in seconds

Definition at line 242 of file Rhythm.h.

References Return.

                                                      { 
                Return( 1.0 / (4.0 * beats.quotient()) * 60.0 / perMinute ); 
        }
Bool Rhythm::operator!= ( Const Rhythm x ) [inline]

Rhythm inequality operator.

Definition at line 103 of file Rhythm.h.

References Return.

                                               {
                Return m_num != x.m_num || m_den != x.m_den;
        }
Rhythm Rhythm::operator* ( Rhythm x ) [inline]

Rhythm times operator.

Definition at line 178 of file Rhythm.h.

References Return, and Rhythm().

                                    {
                Return( Rhythm(quotient() * x.quotient()) );
        }
Rhythm Rhythm::operator* ( Const Real  x ) [inline]

Rhythm multiply by Real operator.

Definition at line 198 of file Rhythm.h.

References Return, and Rhythm().

                                       {
                Return( Rhythm(quotient() * x) );
        }
Rhythm& Rhythm::operator*= ( Const Real  x ) [inline]

Rhythm times-equals operator.

Definition at line 148 of file Rhythm.h.

References Return.

                                         {
                Return( *this = quotient() * x );
        }
Rhythm& Rhythm::operator*= ( Rhythm  x ) [inline]

Rhythm times-equals operator.

Definition at line 153 of file Rhythm.h.

References Return.

                                     {
                Return( *this = quotient() * x.quotient() );
        }
Rhythm Rhythm::operator+ ( Const Real  x ) [inline]

Rhythm add to Real operator.

Definition at line 188 of file Rhythm.h.

References Return, and Rhythm().

                                       {
                Return( Rhythm(quotient() + x) );
        }
Rhythm Rhythm::operator+ ( Rhythm x ) [inline]

Rhythm addition operator.

Definition at line 168 of file Rhythm.h.

References Return, and Rhythm().

                                    {
                Return( Rhythm(quotient() + x.quotient()) );
        }
Rhythm& Rhythm::operator+= ( Rhythm  x ) [inline]

Rhythm plus-equals operator.

Definition at line 133 of file Rhythm.h.

References Return, and Rhythm().

                                     {
                Return( *this = Rhythm(quotient() + x.quotient()) );
        }
Rhythm& Rhythm::operator+= ( Const Real  x ) [inline]

Rhythm plus-equals operator.

Definition at line 128 of file Rhythm.h.

References Return, and Rhythm().

                                         {
                Return( *this = Rhythm(quotient() + x) );
        }
Rhythm Rhythm::operator- ( Rhythm x ) [inline]

Rhythm subtraction operator.

Definition at line 173 of file Rhythm.h.

References Return, and Rhythm().

                                    {
                Return( Rhythm(quotient() - x.quotient()) );
        }
Rhythm Rhythm::operator- ( Const Real  x ) [inline]

Rhythm subtract from Real operator.

Definition at line 193 of file Rhythm.h.

References Return, and Rhythm().

                                       {
                Return( Rhythm(quotient() - x) );
        }
Rhythm& Rhythm::operator-= ( Const Real  x ) [inline]

Rhythm minus-equals operator.

Definition at line 138 of file Rhythm.h.

References Return.

                                         {
                Return( *this = quotient() - x );
        }
Rhythm& Rhythm::operator-= ( Rhythm  x ) [inline]

Rhythm minus-equals operator.

Definition at line 143 of file Rhythm.h.

References Return.

                                     {
                Return( *this = quotient() - x.quotient() );
        }
Rhythm Rhythm::operator/ ( Rhythm x ) [inline]

Rhythm divide operator.

Definition at line 183 of file Rhythm.h.

References Return, and Rhythm().

                                    {
                Return( Rhythm(quotient() / x.quotient()) );
        }
Rhythm Rhythm::operator/ ( Const Real  x ) [inline]

Rhythm divide by Real operator.

Definition at line 203 of file Rhythm.h.

References Return, and Rhythm().

                                       {
                Return( Rhythm(quotient() / x ) );
        }
Rhythm& Rhythm::operator/= ( Const Real  x ) [inline]

Rhythm divide-equals operator.

Definition at line 158 of file Rhythm.h.

References Return.

                                         {
                Return( *this = quotient() / x );
        }
Rhythm& Rhythm::operator/= ( Rhythm  x ) [inline]

Rhythm divide-equals operator.

Definition at line 163 of file Rhythm.h.

References Return.

                                     {
                Return( *this = quotient() / x.quotient() );
        }
Bool Rhythm::operator< ( Const Rhythm x ) [inline]

Rhythm < operator.

Definition at line 118 of file Rhythm.h.

References Return.

                                              {
                Return quotient() < x.quotient();
        }
Bool Rhythm::operator<= ( Const Rhythm x ) [inline]

Rhythm <= operator.

Definition at line 123 of file Rhythm.h.

References Return.

                                               {
                Return quotient() <= x.quotient();
        }
Bool Rhythm::operator== ( Const Rhythm x ) [inline]

Rhythm equality operator.

Definition at line 98 of file Rhythm.h.

References And, and Return.

                                               {
                Return m_num == x.m_num  And m_den == x.m_den;
        }
Bool Rhythm::operator> ( Const Rhythm x ) [inline]

Rhythm > operator.

Definition at line 113 of file Rhythm.h.

References Return.

                                              {
                Return quotient() > x.quotient();
        }
Bool Rhythm::operator>= ( Const Rhythm x ) [inline]

Rhythm >= operator.

Definition at line 108 of file Rhythm.h.

References Return.

                                               {
                Return quotient() >= x.quotient();
        }
String Rhythm::print ( String  s = 0 ) [inline]

Print Rhythm prefixed by String.

Parameters:
sPrefix string

Definition at line 209 of file Rhythm.h.

References If, and Return.

Referenced by operator<<().

                                         {
                If (s)
                        cout << s;
#ifdef _MSC_VER
// Disable Microsoft Visual Studio warning about sprintf()
// until is universal agreement about how to handle its insecurities
#pragma warning(push)
#pragma warning(disable: 4996)
                sprintf(s_buf, "{%d,%d}", m_num, m_den);
#pragma warning(pop)
#else
                sprintf(s_buf, "{%d,%d}", m_num, m_den);
#endif
                Return s_buf;
        }
Static Real Rhythm::tempo ( Void   ) [inline]

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

Definition at line 226 of file Rhythm.h.

References Return.

Referenced by SetTempoScale().

                                { 
                Return s_tempo; 
        }
Static Real Rhythm::tempo ( Real  t ) [inline]

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

Returns:
Current tempo

Definition at line 232 of file Rhythm.h.

References Return.

                                  {
                Real s = s_tempo;
                s_tempo = t;
                Return s;
        }

Friends And Related Function Documentation

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

Definition at line 36 of file Rhythm.h.

{ Return i != p.quotient(); }
Bool operator!= ( Rhythm p,
Real r 
) [friend]

Definition at line 48 of file Rhythm.h.

{ Return p.quotient() != r; }
Bool operator!= ( Rhythm p,
Integer i 
) [friend]

Definition at line 37 of file Rhythm.h.

{ Return p.quotient() != i; }
Bool operator!= ( Real r,
Rhythm p 
) [friend]

Definition at line 47 of file Rhythm.h.

{ Return r != p.quotient(); }
ostream& operator<< ( ostream &  os,
Rhythm r 
) [friend]

Definition at line 65 of file Rhythm.cpp.

{
        os << r.print();
        Return os;
}
Bool operator<= ( Rhythm p,
Integer i 
) [friend]

Definition at line 42 of file Rhythm.h.

{ Return p.quotient() <= i; }
Bool operator<= ( Rhythm p,
Real r 
) [friend]

Definition at line 53 of file Rhythm.h.

{ Return p.quotient() <= r; }
Bool operator<= ( Real r,
Rhythm p 
) [friend]

Definition at line 54 of file Rhythm.h.

{ Return r <= p.quotient(); }
Bool operator<= ( Integer i,
Rhythm p 
) [friend]

Definition at line 43 of file Rhythm.h.

{ Return i <= p.quotient(); }
Bool operator== ( Rhythm p,
Integer i 
) [friend]

Definition at line 35 of file Rhythm.h.

{ Return p.quotient() == i; }
Bool operator== ( Integer i,
Rhythm p 
) [friend]

Definition at line 34 of file Rhythm.h.

{ Return i == p.quotient(); }
Bool operator== ( Real r,
Rhythm p 
) [friend]

Definition at line 45 of file Rhythm.h.

{ Return r == p.quotient(); }
Bool operator== ( Rhythm p,
Real r 
) [friend]

Definition at line 46 of file Rhythm.h.

{ Return p.quotient() == r; }
Bool operator> ( Rhythm p,
Integer i 
) [friend]

Definition at line 40 of file Rhythm.h.

{ Return p.quotient() > i; }
Bool operator> ( Rhythm p,
Real r 
) [friend]

Definition at line 51 of file Rhythm.h.

{ Return p.quotient() > r; }
Bool operator> ( Integer i,
Rhythm p 
) [friend]

Definition at line 41 of file Rhythm.h.

{ Return i > p.quotient(); }
Bool operator> ( Real r,
Rhythm p 
) [friend]

Definition at line 52 of file Rhythm.h.

{ Return r > p.quotient(); }
Bool operator>= ( Rhythm p,
Integer r 
) [friend]

Definition at line 38 of file Rhythm.h.

{ Return p.quotient() >= r; }
Bool operator>= ( Rhythm p,
Real r 
) [friend]

Definition at line 49 of file Rhythm.h.

{ Return p.quotient() >= r; }
Bool operator>= ( Integer i,
Rhythm p 
) [friend]

Definition at line 39 of file Rhythm.h.

{ Return i >= p.quotient(); }
Bool operator>= ( Real r,
Rhythm p 
) [friend]

Definition at line 50 of file Rhythm.h.

{ Return r >= p.quotient(); }
istream& operator>> ( istream &  is,
Rhythm p 
) [friend]

Definition at line 71 of file Rhythm.cpp.

{
        char ch;
        is >> ch && (ch == '{' || ch == '(')
                && is >> p.m_num >> ch && ch == ','
                && is >> p.m_den >> ch && (ch == '}' || ch == '(');
        Return is;
}

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