Pitch Class Reference

Pitch class implements a set of data types, conversions, and operations for musical pitches, scales, and tuning systems. More...

#include <Pitch.h>

List of all members.

Public Member Functions

 operator Integer ()
 operator Real ()
 Pitch ()
 Default Pitch constructor -- sets all fields to 0.
 Pitch (Integer degree)
 Pitch constructor from scale degree.
 Pitch (Integer pitchClass, Integer accidental, Integer octave)
 Pitch constructor from degree/accidental/octave.
 Pitch (String s)
 Pitch constructor from string encoding.
 Pitch (Real hz)
 Pitch constructor from frequency in Hz.
Integer degree () Const
 Degree is the index of this pitch in pitch space.
Integer degree (Integer pc, Integer acc, Integer oct) Const
 Find the degree corresponding to pitch.
Integer pianoKey () Const
 The piano key index.
Integer pianoKey (Integer pc, Integer acc, Integer oct) Const
 Find the piano key corresponding to pitch.
Void transpose (Integer x, Integer &pc, Integer &acc, Integer &oct)
 Transpose pitch.
Void transModuloOctave (Integer x)
 Void transModuloOctave(Integer x) Transposition modulo the number of degrees in the scale (s_nDegrees).
Void invert ()
 Void invert() Inversion modulo the number of degrees in the scale (s_nDegrees).
Bool operator== (Const Pitch &x) Const
 Pitch equality operator.
Bool operator== (Const Integer &x) Const
 Pitch equality operator with Integer.
Bool operator== (Const Real &x) Const
 Pitch equality operator with Real.
Bool operator!= (Const Pitch &x) Const
 Pitch inequality operator.
Bool operator!= (Const Integer &x) Const
 Pitch inequality operator with Integer.
Bool operator!= (Const Real &x) Const
 Pitch inequality operator with Real.
Bool operator>= (Const Pitch &x) Const
 Pitch >= operator.
Bool operator>= (Const Integer &x) Const
 Pitch >= operator with Integer.
Bool operator>= (Const Real &x) Const
 Pitch >= operator with Real.
Bool operator> (Const Pitch &x) Const
 Pitch > operator.
Bool operator> (Const Integer &x) Const
 Pitch > operator with Integer.
Bool operator> (Const Real &x) Const
 Pitch > operator with Real.
Bool operator< (Const Pitch &x) Const
 Pitch < operator.
Bool operator< (Const Integer &x) Const
 Pitch < operator with Integer.
Bool operator< (Const Real &x) Const
 Pitch < operator with Real.
Bool operator<= (Const Pitch &x) Const
 Pitch <= operator.
Bool operator<= (Const Integer &x) Const
 Pitch <= operator with Integer.
Bool operator<= (Const Real &x) Const
 Pitch <= operator with Real.
Pitchoperator+= (Const Pitch x)
 Pitch increment operator.
Pitchoperator+= (Const Integer x)
 Pitch increment operator with Integer.
Pitchoperator+= (Const Real x)
 Pitch increment operator with Real.
Pitchoperator-= (Const Pitch x)
 Pitch decrement operator.
Pitchoperator-= (Const Integer x)
 Pitch decrement operator with Integer.
Pitchoperator-= (Const Real x)
 Pitch decrement operator with Real.
Pitchoperator *= (Const Pitch x)
 Pitch multiply scale operator.
Pitchoperator *= (Const Integer x)
 Pitch multiply scale operator with Integer.
Pitchoperator *= (Const Real x)
 Pitch multiply scale operator with Real.
Pitchoperator/= (Const Pitch x)
 Pitch divide scale operator.
Pitchoperator/= (Const Integer x)
 Pitch divide scale operator with Integer.
Pitchoperator/= (Const Real x)
 Pitch divide scale operator with Real.
Pitch operator+ (Const Pitch &x)
 Pitch addition operator.
Pitch operator+ (Const Integer x)
 Pitch addition operator with Integer.
Pitch operator+ (Const Real x)
 Pitch addition operator with Real.
Pitch operator- (Const Pitch &x)
 Pitch subtraction operator.
Pitch operator- (Const Integer x)
 Pitch subtraction operator with Integer.
Pitch operator- (Const Real x)
 Pitch subtraction operator with Real.
Pitch operator * (Const Pitch &x)
 Pitch multiplication operator.
Pitch operator * (Const Integer x)
 Pitch multiplication operator with Integer.
Pitch operator * (Const Real x)
 Pitch multiplication operator with Real.
Pitch operator/ (Const Pitch &x)
 Pitch division operator.
Pitch operator/ (Const Integer x)
 Pitch division operator with Integer.
Pitch operator/ (Const Real x)
 Pitch division operator with Real.
Pitch operator% (Const Pitch x)
 Pitch modulo operator.
Pitch operator% (Const Integer x)
 Pitch modulo operator with Integer.
Pitch operator% (Const Real x)
 Pitch modulo operator with Real.
String print (String s=0) Const
 Print pitch prefixed by string.
Integer pitchClass () Const
 The pitch class of this pitch.
Integer accidental () Const
 The accidental of this pitch.
Integer octave () Const
 The octave of this pitch.
Real hertz () Const
 The frequency in Hz of this pitch.
Static Void HzReference (Real ref)
 Set the reference frequency of the scale.
Static Real HzReference ()
 Get the reference frequency of the scale.
Static Void SetLowestKey (Integer ref)
 Set the index of the lowest degree in the scale's gamut.
Static Void SetHighestKey (Integer ref)
 Set the index of the highest degree in the scale's gamut.
Static Void SetDegrees (Integer ref)
 Set the number of degrees in the scale's gamut.
Integer isPitchClass (char c) Const
 Returns the chromatic degree of a diatonic step or -1 if not matched.
Integer isAccidental (char c) Const
 Returns an offset for a chromatic degree.

Friends

ostream & operator<< (ostream &, Pitch &)
istream & operator>> (istream &, Pitch &)
Bool operator== (Integer &i, Pitch &p)
Bool operator== (Pitch &p, Integer &i)
Bool operator!= (Integer &i, Pitch &p)
Bool operator!= (Pitch &p, Integer &i)
Bool operator>= (Pitch &p, Integer &r)
Bool operator>= (Integer &i, Pitch &p)
Bool operator> (Pitch &p, Integer &i)
Bool operator> (Integer &i, Pitch &p)
Bool operator<= (Pitch &p, Integer &i)
Bool operator<= (Integer &i, Pitch &p)
Bool operator== (Real &r, Pitch &p)
Bool operator== (Pitch &p, Real &r)
Bool operator!= (Real &r, Pitch &p)
Bool operator!= (Pitch &p, Real &r)
Bool operator>= (Pitch &p, Real &r)
Bool operator>= (Real &r, Pitch &p)
Bool operator> (Pitch &p, Real &r)
Bool operator> (Real &r, Pitch &p)
Bool operator<= (Pitch &p, Real &r)
Bool operator<= (Real &r, Pitch &p)


Detailed Description

Pitch class implements a set of data types, conversions, and operations for musical pitches, scales, and tuning systems.

It operates by default on the equal tempered dodecaphonic scale, but can trivially be configured to just scales, microtonal scales, and non octave-based scales.

Definition at line 34 of file Pitch.h.


Constructor & Destructor Documentation

Pitch::Pitch (  )  [inline]

Default Pitch constructor -- sets all fields to 0.

Definition at line 67 of file Pitch.h.

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

00067 : m_pc(0), m_acc(0), m_oct(0) { }

Pitch::Pitch ( Integer  degree  )  [inline]

Pitch constructor from scale degree.

Parameters:
degree Scale degree

Definition at line 71 of file Pitch.h.

References transpose().

00071                               : m_pc(0), m_acc(0), m_oct(0) { 
00072                 transpose( degree, m_pc, m_acc, m_oct ); 
00073         }

Pitch::Pitch ( Integer  pitchClass,
Integer  accidental,
Integer  octave 
) [inline]

Pitch constructor from degree/accidental/octave.

Parameters:
pitchClass Scale degree
accidental Accidental
octave Octave

Definition at line 79 of file Pitch.h.

00079 : m_pc(pitchClass), m_acc(accidental), m_oct(octave) { }

Pitch::Pitch ( String  s  ) 

Pitch constructor from string encoding.

Parameters:
s String containing pitch encoding

Definition at line 77 of file Pitch.cpp.

References Else, If, isAccidental(), isPitchClass(), Return, and While.

00077                      : 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 }

Pitch::Pitch ( Real  hz  )  [inline]

Pitch constructor from frequency in Hz.

Parameters:
hz Frequency of pitch in Hz. The nearest lower pitch class is chosen. For example, Pitch(440.5) chooses A4.

Definition at line 88 of file Pitch.h.

References For, If, Pitch(), and Return.

00088                        : m_pc(0), m_acc(0), m_oct(0) {
00089                 For(Integer pc = s_lowestDegree; pc < s_lowestDegree+s_highestDegree; pc++) {
00090                         Pitch p = Pitch(pc);
00091                         Real x = p.hertz(); // get the Hz equivalent of this pitch
00092                         If ( x > hz) {                          // have we passed our target?
00093                                 pc -= 1;
00094                                 *this = Pitch(pc); // return the pitch
00095                                 Return;
00096                         }
00097                 }
00098                 // If we get here, the hz value is out of range
00099                 *this = Pitch(s_highestDegree); // Pitch is out of range, clip at top of range
00100         }


Member Function Documentation

Integer Pitch::accidental (  )  [inline]

The accidental of this pitch.

Definition at line 449 of file Pitch.h.

References Return.

Referenced by Accidental(), and hertz().

00449 { Return m_acc; }

Integer Pitch::degree ( Integer  pc,
Integer  acc,
Integer  oct 
) [inline]

Find the degree corresponding to pitch.

Parameters:
pc pitch class
acc accidental
oct octave
Returns:
The degree (index) of the specified pitch

Definition at line 114 of file Pitch.h.

References Return.

00114                                                                    {
00115                 Return((pc + acc) + s_nDegrees * oct); 
00116         }

Integer Pitch::degree (  )  [inline]

Degree is the index of this pitch in pitch space.

Returns:
The index of this pitch in pitch space. For example, Pitch p(A4); p.degree(); returns 48

Definition at line 105 of file Pitch.h.

References Return.

Referenced by LinearInterpolate(), operator *(), operator *=(), operator Integer(), operator!=(), operator%(), operator+(), operator-(), operator/(), operator/=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().

00105                                {
00106                 Return( degree(m_pc, m_acc, m_oct) ); 
00107         }

Real Pitch::hertz (  )  [inline]

The frequency in Hz of this pitch.

Definition at line 455 of file Pitch.h.

References accidental(), octave(), pitchClass(), Pow(), and Return.

Referenced by operator *(), operator *=(), operator Real(), operator!=(), operator%(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), and PitchToHertz().

00455                            {
00456                 Real R = s_HzReference;
00457                 Real k = pitchClass() + accidental() - 9.0;
00458                 Real o = octave() - 4.0;
00459                 Return( R * Pow(2.0, o + k / Real(s_nDegrees) ) );
00460         }

Static Real Pitch::HzReference (  )  [inline]

Get the reference frequency of the scale.

Definition at line 466 of file Pitch.h.

References Return.

Referenced by KeyToHertz().

00466 { Return( s_HzReference); }

Static Void Pitch::HzReference ( Real  ref  )  [inline]

Set the reference frequency of the scale.

Definition at line 463 of file Pitch.h.

00463 { s_HzReference = ref; }

Void Pitch::invert (  )  [inline]

Void invert() Inversion modulo the number of degrees in the scale (s_nDegrees).

Definition at line 172 of file Pitch.h.

References Mod(), and transpose().

00172                       {
00173                 Integer p = Mod( m_pc + m_acc, s_nDegrees );
00174                 p = Mod( s_nDegrees - p, s_nDegrees );
00175                 transpose( p, m_pc = 0, m_acc = 0, m_oct );
00176         }

Integer Pitch::isAccidental ( char  c  )  [inline]

Returns an offset for a chromatic degree.

Accidentals are {#,S,s}=sharp, {N,n,<nil>}=natural, {B,b,F,f}=flat, X=double-sharp, V=double-flat Accidentals in a pitch specification may be repeated, so that Abb equals AV equals Bbbbb, etc.

Returns:
-3 if not a pitch class name

Definition at line 497 of file Pitch.h.

References Break, and Return.

Referenced by operator>>(), and Pitch().

00497                                            {
00498                 switch (c) {
00499                 case '#':           Return  1;  Break;  // sharp
00500                 case 'S': case 's': Return  1;  Break;  // sharp
00501                 case 'N': case 'n': Return  0;  Break;  // natural
00502                 case 'B': case 'b':     Return -1;      Break;  // flat
00503                 case 'F': case 'f':     Return -1;      Break;  // flat
00504                 case 'X': case 'x':     Return  2;      Break;  // double-sharp
00505                 case 'V': case 'v':     Return -2;      Break;  // double-flat
00506                 default: Return -3;             Break; // may be an octave spec. with no accidental
00507                 }
00508         }

Integer Pitch::isPitchClass ( char  c  )  [inline]

Returns the chromatic degree of a diatonic step or -1 if not matched.

Pitch classes are the upper- or lower-case letters A-G

Returns:
-1 if not a pitch class name

Definition at line 480 of file Pitch.h.

References Break, and Return.

Referenced by operator>>(), and Pitch().

00480                                            {
00481                 switch (c) {
00482                 case 'C': case 'c': Return 0; Break;
00483                 case 'D': case 'd': Return 2; Break;
00484                 case 'E': case 'e': Return 4; Break;
00485                 case 'F': case 'f': Return 5; Break;
00486                 case 'G': case 'g': Return 7; Break;
00487                 case 'A': case 'a': Return 9; Break;
00488                 case 'B': case 'b': Return 11; Break;
00489                 default: Return -1;
00490                 }
00491         }

Integer Pitch::octave (  )  [inline]

The octave of this pitch.

Definition at line 452 of file Pitch.h.

References Return.

Referenced by hertz(), and Octave().

00452 { Return m_oct; }

Pitch Pitch::operator * ( Const Real  x  )  [inline]

Pitch multiplication operator with Real.

Definition at line 385 of file Pitch.h.

References hertz(), and Return.

00385                                       {
00386                 Return( hertz() * x );
00387         }

Pitch Pitch::operator * ( Const Integer  x  )  [inline]

Pitch multiplication operator with Integer.

Definition at line 380 of file Pitch.h.

References degree(), and Return.

00380                                          {
00381                 Return( degree() * x );
00382         }

Pitch Pitch::operator * ( Const Pitch x  )  [inline]

Pitch multiplication operator.

Definition at line 375 of file Pitch.h.

References degree(), and Return.

00375                                         {
00376                 Return( degree() * x.degree() );
00377         }

Pitch& Pitch::operator *= ( Const Real  x  )  [inline]

Pitch multiply scale operator with Real.

Definition at line 318 of file Pitch.h.

References hertz(), Pitch(), and Return.

00318                                         {
00319                 Real hz = hertz() * x;
00320                 Return( *this = Pitch(hz) );
00321         }

Pitch& Pitch::operator *= ( Const Integer  x  )  [inline]

Pitch multiply scale operator with Integer.

Definition at line 312 of file Pitch.h.

References degree(), Pitch(), and Return.

00312                                            {
00313                 Integer d = degree() * x;
00314                 Return( *this = Pitch(d) );
00315         }

Pitch& Pitch::operator *= ( Const Pitch  x  )  [inline]

Pitch multiply scale operator.

Definition at line 306 of file Pitch.h.

References degree(), Pitch(), and Return.

00306                                          {
00307                 Integer d = degree() * x.degree();
00308                 Return( *this = Pitch(d) );
00309         }

Pitch::operator Integer (  )  [inline]

Definition at line 63 of file Pitch.h.

References degree(), and Return.

00063 { Return degree(); }

Pitch::operator Real (  )  [inline]

Definition at line 64 of file Pitch.h.

References hertz(), and Return.

00064 { Return hertz(); }

Bool Pitch::operator!= ( Const Real x  )  [inline]

Pitch inequality operator with Real.

Definition at line 204 of file Pitch.h.

References hertz(), and Return.

00204                                              {
00205                 Return hertz() != x;
00206         }

Bool Pitch::operator!= ( Const Integer x  )  [inline]

Pitch inequality operator with Integer.

Definition at line 199 of file Pitch.h.

References degree(), and Return.

00199                                                 {
00200                 Return degree() != x;
00201         }

Bool Pitch::operator!= ( Const Pitch x  )  [inline]

Pitch inequality operator.

Definition at line 194 of file Pitch.h.

References degree(), and Return.

00194                                               {
00195                 Return degree() != x.degree();
00196         }

Pitch Pitch::operator% ( Const Real  x  )  [inline]

Pitch modulo operator with Real.

Definition at line 418 of file Pitch.h.

References hertz(), Mod(), Pitch(), and Return.

00418                                       {
00419                 Real hz = Mod(hertz(), x);
00420                 Return( Pitch(hz) );
00421         }

Pitch Pitch::operator% ( Const Integer  x  )  [inline]

Pitch modulo operator with Integer.

Definition at line 412 of file Pitch.h.

References degree(), Mod(), and Return.

00412                                          {
00413                 Integer d = Mod(degree(), x);
00414                 Return( d );
00415         }

Pitch Pitch::operator% ( Const Pitch  x  )  [inline]

Pitch modulo operator.

Definition at line 406 of file Pitch.h.

References degree(), Mod(), and Return.

00406                                        {
00407                 Integer d = Mod(degree(), x.degree());
00408                 Return( d );
00409         }

Pitch Pitch::operator+ ( Const Real  x  )  [inline]

Pitch addition operator with Real.

Definition at line 353 of file Pitch.h.

References hertz(), Pitch(), and Return.

00353                                       {
00354                 Real hz = hertz() * x;
00355                 Return( Pitch(hz) );
00356         }

Pitch Pitch::operator+ ( Const Integer  x  )  [inline]

Pitch addition operator with Integer.

Definition at line 348 of file Pitch.h.

References degree(), and Return.

00348                                          {
00349                 Return( degree() + x );
00350         }

Pitch Pitch::operator+ ( Const Pitch x  )  [inline]

Pitch addition operator.

Definition at line 343 of file Pitch.h.

References degree(), and Return.

00343                                         {
00344                 Return( degree() + x.degree() );
00345         }

Pitch& Pitch::operator+= ( Const Real  x  )  [inline]

Pitch increment operator with Real.

Definition at line 281 of file Pitch.h.

References hertz(), Pitch(), and Return.

00281                                         {
00282                 Real hz = hertz() + x;
00283                 *this = Pitch( hz );
00284                 Return( *this );
00285         }

Pitch& Pitch::operator+= ( Const Integer  x  )  [inline]

Pitch increment operator with Integer.

Definition at line 275 of file Pitch.h.

References Return, and transpose().

00275                                            {
00276                 transpose( x, m_pc, m_acc, m_oct );
00277                 Return( *this );
00278         }

Pitch& Pitch::operator+= ( Const Pitch  x  )  [inline]

Pitch increment operator.

Definition at line 269 of file Pitch.h.

References Return, and transpose().

00269                                          {
00270                 transpose( x.degree(), m_pc, m_acc, m_oct );
00271                 Return( *this );
00272         }

Pitch Pitch::operator- ( Const Real  x  )  [inline]

Pitch subtraction operator with Real.

Definition at line 369 of file Pitch.h.

References hertz(), and Return.

00369                                       {
00370                 Real hz = hertz() - x;
00371                 Return( hz );
00372         }

Pitch Pitch::operator- ( Const Integer  x  )  [inline]

Pitch subtraction operator with Integer.

Definition at line 364 of file Pitch.h.

References degree(), and Return.

00364                                          {
00365                 Return( degree() - x );
00366         }

Pitch Pitch::operator- ( Const Pitch x  )  [inline]

Pitch subtraction operator.

Definition at line 359 of file Pitch.h.

References degree(), and Return.

00359                                         {
00360                 Return( degree() - x.degree() );
00361         }

Pitch& Pitch::operator-= ( Const Real  x  )  [inline]

Pitch decrement operator with Real.

Definition at line 300 of file Pitch.h.

References hertz(), Pitch(), and Return.

00300                                         {
00301                 Real hz = hertz() - x;
00302                 Return( *this = Pitch( hz ) );
00303         }

Pitch& Pitch::operator-= ( Const Integer  x  )  [inline]

Pitch decrement operator with Integer.

Definition at line 294 of file Pitch.h.

References Return, and transpose().

00294                                            {
00295                 transpose( -x, m_pc, m_acc, m_oct );
00296                 Return( *this );
00297         }

Pitch& Pitch::operator-= ( Const Pitch  x  )  [inline]

Pitch decrement operator.

Definition at line 288 of file Pitch.h.

References Return, and transpose().

00288                                          {
00289                 transpose( -x.degree(), m_pc, m_acc, m_oct );
00290                 Return( *this );
00291         }

Pitch Pitch::operator/ ( Const Real  x  )  [inline]

Pitch division operator with Real.

Definition at line 400 of file Pitch.h.

References hertz(), Pitch(), and Return.

00400                                       {
00401                 Real hz = hertz() / x;
00402                 Return( Pitch(hz) );
00403         }

Pitch Pitch::operator/ ( Const Integer  x  )  [inline]

Pitch division operator with Integer.

Definition at line 395 of file Pitch.h.

References degree(), and Return.

00395                                          {
00396                 Return( degree() / x );
00397         }

Pitch Pitch::operator/ ( Const Pitch x  )  [inline]

Pitch division operator.

Definition at line 390 of file Pitch.h.

References degree(), and Return.

00390                                         {
00391                 Return( degree() / x.degree() );
00392         }

Pitch& Pitch::operator/= ( Const Real  x  )  [inline]

Pitch divide scale operator with Real.

Definition at line 337 of file Pitch.h.

References hertz(), Pitch(), and Return.

00337                                         {
00338                 Real hz = hertz() / x;
00339                 Return( *this = Pitch(hz) );
00340         }

Pitch& Pitch::operator/= ( Const Integer  x  )  [inline]

Pitch divide scale operator with Integer.

Definition at line 330 of file Pitch.h.

References degree(), Pitch(), and Return.

00330                                            {
00331                 Integer d = degree() / x;
00332                 Return( *this = Pitch(d) );
00333 
00334         }

Pitch& Pitch::operator/= ( Const Pitch  x  )  [inline]

Pitch divide scale operator.

Definition at line 324 of file Pitch.h.

References degree(), Pitch(), and Return.

00324                                          {
00325                 Integer d = degree() / x.degree();
00326                 Return( *this = Pitch(d) );
00327         }

Bool Pitch::operator< ( Const Real x  )  [inline]

Pitch < operator with Real.

Definition at line 249 of file Pitch.h.

References hertz(), and Return.

00249                                             {
00250                 Return hertz() < x;
00251         }

Bool Pitch::operator< ( Const Integer x  )  [inline]

Pitch < operator with Integer.

Definition at line 244 of file Pitch.h.

References degree(), and Return.

00244                                                {
00245                 Return degree() < x;
00246         }

Bool Pitch::operator< ( Const Pitch x  )  [inline]

Pitch < operator.

Definition at line 239 of file Pitch.h.

References degree(), and Return.

00239                                              {
00240                 Return degree() < x.degree();
00241         }

Bool Pitch::operator<= ( Const Real x  )  [inline]

Pitch <= operator with Real.

Definition at line 264 of file Pitch.h.

References hertz(), and Return.

00264                                              {
00265                 Return hertz() <= x;
00266         }

Bool Pitch::operator<= ( Const Integer x  )  [inline]

Pitch <= operator with Integer.

Definition at line 259 of file Pitch.h.

References degree(), and Return.

00259                                                 {
00260                 Return degree() <= x;
00261         }

Bool Pitch::operator<= ( Const Pitch x  )  [inline]

Pitch <= operator.

Definition at line 254 of file Pitch.h.

References degree(), and Return.

00254                                               {
00255                 Return degree() <= x.degree();
00256         }

Bool Pitch::operator== ( Const Real x  )  [inline]

Pitch equality operator with Real.

Definition at line 189 of file Pitch.h.

References hertz(), and Return.

00189                                              {
00190                 Return hertz() == x;
00191         }

Bool Pitch::operator== ( Const Integer x  )  [inline]

Pitch equality operator with Integer.

Definition at line 184 of file Pitch.h.

References degree(), and Return.

00184                                                 {
00185                 Return degree() == x;
00186         }

Bool Pitch::operator== ( Const Pitch x  )  [inline]

Pitch equality operator.

Definition at line 179 of file Pitch.h.

References degree(), and Return.

00179                                               {
00180                 Return degree() == x.degree();
00181         }

Bool Pitch::operator> ( Const Real x  )  [inline]

Pitch > operator with Real.

Definition at line 234 of file Pitch.h.

References hertz(), and Return.

00234                                             {
00235                 Return hertz() > x;
00236         }

Bool Pitch::operator> ( Const Integer x  )  [inline]

Pitch > operator with Integer.

Definition at line 229 of file Pitch.h.

References degree(), and Return.

00229                                                {
00230                 Return degree() > x;
00231         }

Bool Pitch::operator> ( Const Pitch x  )  [inline]

Pitch > operator.

Definition at line 224 of file Pitch.h.

References degree(), and Return.

00224                                              {
00225                 Return degree() > x.degree();
00226         }

Bool Pitch::operator>= ( Const Real x  )  [inline]

Pitch >= operator with Real.

Definition at line 219 of file Pitch.h.

References hertz(), and Return.

00219                                              {
00220                 Return hertz() >= x;
00221         }

Bool Pitch::operator>= ( Const Integer x  )  [inline]

Pitch >= operator with Integer.

Definition at line 214 of file Pitch.h.

References degree(), and Return.

00214                                                 {
00215                 Return degree() >= x;
00216         }

Bool Pitch::operator>= ( Const Pitch x  )  [inline]

Pitch >= operator.

Definition at line 209 of file Pitch.h.

References degree(), and Return.

00209                                               {
00210                 Return degree() >= x.degree();
00211         }

Integer Pitch::pianoKey ( Integer  pc,
Integer  acc,
Integer  oct 
) [inline]

Find the piano key corresponding to pitch.

Parameters:
pc pitch class
acc accidental
oct octave
Returns:
The piano key index of the specified pitch

Definition at line 129 of file Pitch.h.

References Return.

00129                                                                      {
00130                 Return((pc + acc) + s_nDegrees * (oct - 1) + 3); 
00131         }

Integer Pitch::pianoKey (  )  [inline]

The piano key index.

Returns:
Piano key index of this Pitch

Definition at line 120 of file Pitch.h.

References Return.

00120                                  {
00121                 Return( pianoKey(m_pc, m_acc, m_oct) ); 
00122         }

Integer Pitch::pitchClass (  )  [inline]

The pitch class of this pitch.

Definition at line 446 of file Pitch.h.

References Return.

Referenced by hertz(), and PitchClass().

00446 { Return m_pc; }

String Pitch::print ( String  s = 0  )  [inline]

Print pitch prefixed by string.

Parameters:
s String to prefix

Definition at line 425 of file Pitch.h.

References Break, Character, Else, If, and Return.

Referenced by operator<<().

00425                                          {
00426                 If (s)
00427                         cout << s;
00428                 Character pc = s_pcNames[ m_pc ];
00429                 Character acc;
00430                 switch (m_acc) {
00431                 case 0: acc = 0; Break;                 // natural
00432                 case 1: acc = 's'; Break;               // sharp
00433                 case -1: acc = 'b'; Break;              // flat
00434                 case 2: acc = 'x'; Break;               // double-sharp
00435                 case -2: acc = 'v'; Break;              // double-flat
00436                 default: acc = 0; Break;                // natural
00437                 }
00438                 If (acc)
00439                         sprintf(s_buf, "%c%c%d", pc, acc, m_oct);
00440                 Else
00441                         sprintf(s_buf, "%c%d", pc, m_oct);
00442                 Return s_buf;
00443         }

Static Void Pitch::SetDegrees ( Integer  ref  )  [inline]

Set the number of degrees in the scale's gamut.

Definition at line 475 of file Pitch.h.

Referenced by SetDegrees().

00475 { s_nDegrees = ref; }

Static Void Pitch::SetHighestKey ( Integer  ref  )  [inline]

Set the index of the highest degree in the scale's gamut.

Definition at line 472 of file Pitch.h.

00472 { s_highestDegree = ref; }

Static Void Pitch::SetLowestKey ( Integer  ref  )  [inline]

Set the index of the lowest degree in the scale's gamut.

Definition at line 469 of file Pitch.h.

00469 { s_lowestDegree = ref; }

Void Pitch::transModuloOctave ( Integer  x  )  [inline]

Void transModuloOctave(Integer x) Transposition modulo the number of degrees in the scale (s_nDegrees).

Parameters:
x Degrees to transpose

Definition at line 164 of file Pitch.h.

References transpose().

00164                                           {
00165                 Integer o = m_oct;
00166                 transpose( x, m_pc, m_acc, m_oct );
00167                 m_oct = o;
00168         }

Void Pitch::transpose ( Integer  x,
Integer pc,
Integer acc,
Integer oct 
) [inline]

Transpose pitch.

Parameters:
x Number of degrees to transpose by
pc pitch class
acc accidental
oct octave
Returns:
The transposed Pitch

Definition at line 139 of file Pitch.h.

References Break, Else, If, and While.

Referenced by invert(), operator+=(), operator-=(), Pitch(), and transModuloOctave().

00139                                                                            {
00140                 pc += acc + x;  // add the pitch, its accidental and the transposition to get raw semitones
00141                 acc = 0; // clear the accidental
00142                 While ( pc >= s_nDegrees ) { pc = pc - s_nDegrees; oct++; }
00143                 While ( pc < 0 ) { pc = pc + s_nDegrees; oct--; }
00144                 // cvt. to diatonic
00145                 switch (pc) {                   // adjust for enharmonic spelling
00146                 case 0: Break;                                                                                                  // C
00147                 case 1: If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // C# Db
00148                 case 2: Break;                                                                                                  // D
00149                 case 3: If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // D# Eb
00150                 case 4: Break;                                                                                                  // E
00151                 case 5: Break;                                                                                                  // F
00152                 case 6: If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // F# Gb
00153                 case 7: Break;                                                                                                  // G
00154                 case 8: If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // G# Ab
00155                 case 9: Break;                                                                                                  // A
00156                 case 10:If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // A# Bb
00157                 case 11: Break;                                                                                                 // B
00158                 }
00159         }


Friends And Related Function Documentation

Bool operator!= ( Pitch p,
Real r 
) [friend]

Definition at line 53 of file Pitch.h.

00053 { Return p.hertz() != r; }

Bool operator!= ( Real r,
Pitch p 
) [friend]

Definition at line 52 of file Pitch.h.

00052 { Return r != p.hertz(); }

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

Definition at line 42 of file Pitch.h.

00042 { Return p.degree() != i; }

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

Definition at line 41 of file Pitch.h.

00041 { Return i != p.degree(); }

ostream& operator<< ( ostream &  os,
Pitch p 
) [friend]

Definition at line 24 of file Pitch.cpp.

00025 {
00026         os << p.print();
00027         Return os;
00028 }

Bool operator<= ( Real r,
Pitch p 
) [friend]

Definition at line 59 of file Pitch.h.

00059 { Return r <= p.hertz(); }

Bool operator<= ( Pitch p,
Real r 
) [friend]

Definition at line 58 of file Pitch.h.

00058 { Return p.hertz() <= r; }

Bool operator<= ( Integer i,
Pitch p 
) [friend]

Definition at line 48 of file Pitch.h.

00048 { Return i <= p.degree(); }

Bool operator<= ( Pitch p,
Integer i 
) [friend]

Definition at line 47 of file Pitch.h.

00047 { Return p.degree() <= i; }

Bool operator== ( Pitch p,
Real r 
) [friend]

Definition at line 51 of file Pitch.h.

00051 { Return p.hertz() == r; }

Bool operator== ( Real r,
Pitch p 
) [friend]

Definition at line 50 of file Pitch.h.

00050 { Return r == p.hertz(); }

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

Definition at line 40 of file Pitch.h.

00040 { Return p.degree() == i; }

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

Definition at line 39 of file Pitch.h.

00039 { Return i == p.degree(); }

Bool operator> ( Real r,
Pitch p 
) [friend]

Definition at line 57 of file Pitch.h.

00057 { Return r > p.hertz(); }

Bool operator> ( Pitch p,
Real r 
) [friend]

Definition at line 56 of file Pitch.h.

00056 { Return p.hertz() > r; }

Bool operator> ( Integer i,
Pitch p 
) [friend]

Definition at line 46 of file Pitch.h.

00046 { Return i > p.degree(); }

Bool operator> ( Pitch p,
Integer i 
) [friend]

Definition at line 45 of file Pitch.h.

00045 { Return p.degree() > i; }

Bool operator>= ( Real r,
Pitch p 
) [friend]

Definition at line 55 of file Pitch.h.

00055 { Return r >= p.hertz(); }

Bool operator>= ( Pitch p,
Real r 
) [friend]

Definition at line 54 of file Pitch.h.

00054 { Return p.hertz() >= r; }

Bool operator>= ( Integer i,
Pitch p 
) [friend]

Definition at line 44 of file Pitch.h.

00044 { Return i >= p.degree(); }

Bool operator>= ( Pitch p,
Integer r 
) [friend]

Definition at line 43 of file Pitch.h.

00043 { Return p.degree() >= r; }

istream& operator>> ( istream &  is,
Pitch p 
) [friend]

Definition at line 40 of file Pitch.cpp.

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 }


The documentation for this class was generated from the following files:
Generated on Fri Sep 8 23:21:13 2006 for MusimatLib by  doxygen 1.4.7