- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatLib/Rhythm.cpp

Go to the documentation of this file.

    00001 /* $Revision: 1.2 $ $Date: 2006/09/09 06:22:54 $ $Author: dgl $ $Name:  $ $Id: _rhythm_8cpp-source.html,v 1.2 2006/09/09 06:22:54 dgl Exp $ */
    00002 // The Musimat Tutorial © 2006 Gareth Loy
    00003 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy
    00004 // and published exclusively by The MIT Press.
    00005 // This program is released WITHOUT ANY WARRANTY; without even the implied
    00006 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
    00008 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
    00009 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
    00010 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
    00011 // The Musimat website:                 http://www.musimat.com/
    00012 // This program is released under the terms of the GNU General Public License
    00013 // available here:                      http://www.gnu.org/licenses/gpl.txt
    00014
    00015 #include "Musimat.h"
    00016
    00017 // There are 4 quarter notes in a whole note
    00018 Real Rhythm::s_fourQuarters = 4.0;
    00019
    00020 // Implicit coefficient applied to all rhythmic values globally.
    00021 // Initial value is 1.0, equal to a quarter note at MM=60 BPM.
    00022 Real Rhythm::s_tempo = Rhythm::mmInit( 1.0/4.0, 60.0 );
    00023
    00024 // Private buffer to format strings in
    00025 Character Rhythm::s_buf[128];
    00026
    00027 Void SetTempoScale( Real ts )
    00028 {
    00029         Rhythm::tempo(ts);
    00030 }
    00031
    00032 Real metronome( Rhythm B, Real T )
    00033 {
    00034         Return( 1.0 / (4.0 * B.absDuration()) * 60.0 / T );
    00035 }
    00036
    00037 Real Duration( Real x )
    00038 {
    00039         Rhythm(y);
    00040         Return y.duration();
    00041 }
    00042
    00043 Real Duration( Integer n, Integer d)
    00044 {
    00045         Rhythm y = Rhythm(n, d);
    00046         Return y.duration();
    00047 }
    00048
    00049 Real AbsDuration( Real x )
    00050 {
    00051         Rhythm(y);
    00052         Return y.absDuration();
    00053 }
    00054
    00055 Real Duration( Rhythm y )
    00056 {
    00057         Return y.absDuration();
    00058 }
    00059
    00060 Real AbsDuration( Rhythm y )
    00061 {
    00062         Return y.absDuration();
    00063 }
    00064
    00065 ostream& operator<<( ostream& os, Rhythm& r )
    00066 {
    00067         os << r.print();
    00068         Return os;
    00069 }
    00070
    00071 istream& operator>>( istream& is, Rhythm& p )
    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 }
    00079
    00080 Rhythm Whole = Duration( 1 ),
    00081         Half = Duration( 1, 2 ),
    00082         Quarter = Duration( 1, 4 ),
    00083         Eighth = Duration( 1, 8 ),
    00084         Sixteenth = Duration( 1, 16 )
    00085 ;
    00086