• Main Page
  • Modules
  • Classes
  • Files
  • File List
  • File Members

/Users/garethloy/Musimathics/Musimat1.2/MusimatLib/Pitch.cpp

Go to the documentation of this file.
00001 /* $Revision: 1.5 $ $Date: 2006/09/08 18:55:37 $ $Author: dgl $ $Name:  $ $Id: Pitch.cpp,v 1.5 2006/09/08 18:55:37 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 char Pitch::s_buf[16];                                          
00018 String Pitch::s_pcNames = (char*)"CCDDEFFGGAAB";        
00019 Real Pitch::s_HzReference = 440.0;                      
00020 Integer Pitch::s_nDegrees = 12;                         
00021 Integer Pitch::s_lowestDegree = 0;                      
00022 Integer Pitch::s_highestDegree = 88;            
00023 
00024 ostream& operator<<( ostream& os, Pitch& p ) 
00025 {
00026         os << p.print();
00027         Return os;
00028 }
00029 
00030 inline Bool isnumeric(char c)
00031 {
00032         Return c >= '0' && c <= '9';
00033 }
00034 
00035 inline Bool inRange(char c, char lb, char ub)
00036 {
00037         Return c >= lb && c <= ub;
00038 }
00039 
00040 istream& operator>>( istream& is, Pitch& p ) 
00041 {
00042         //char buf[16];
00043         //cin >> buf;
00044         //p = Pitch(buf);
00045         //Return is;
00046         char c;
00047         cin >> c;
00048         If ((p.m_pc = p.isPitchClass(c)) == -1) {
00049                 cin.unget();
00050                 Return is;
00051         }
00052 
00053         Integer acc = 0;
00054         While (cin >> c && ((acc = p.isAccidental(c)) != -3)) {
00055                 p.m_acc += acc;
00056         }
00057 
00058         If (!inRange(c, '0', '9')) {
00059                 cin.unget();
00060                 Return is;
00061         } Else {
00062                 char buf[16];
00063                 char* b = buf;
00064                 Integer cnt = 0;
00065                 cin.unget(); 
00066                 While (!cin.eof() && cin >> c && isnumeric(c) && cnt++ < 16) {
00067 //                      char y = cin.eof();
00068                         *b++ = c;
00069                 }
00070                 cin.unget();
00071                 *b = '\0';
00072                 p.m_oct = atoi(buf);
00073         }
00074         Return is;
00075 }
00076 
00077 Pitch::Pitch(String s) : m_pc(0), m_acc(0), m_oct(0) {
00078         If ((m_pc = isPitchClass(*s)) == -1)
00079                 Return;
00080 
00081         Integer acc = 0;
00082         While ((acc = isAccidental(*++s)) != -3) {
00083                 m_acc += acc;
00084         }
00085 
00086         If (*s == 0)
00087                 Return;
00088         Else
00089                 m_oct = atoi(s);
00090 }
00091 

Generated on Fri Nov 26 2010 16:18:25 for MusimatLib by  doxygen 1.7.2