Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00043
00044
00045
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
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