Public Member Functions | Friends

Pitch Class Reference

Pitch implements representation and manipulation of musical pitches. 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 implements representation and manipulation of musical pitches.

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. Pitch class implements a set of data types, conversions, and operations for musical pitches, scales, and tuning systems.

Definition at line 37 of file Pitch.h.


Constructor & Destructor Documentation

Pitch::Pitch (  ) [inline]

Default Pitch constructor -- sets all fields to 0.

Definition at line 70 of file Pitch.h.

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

: m_pc(0), m_acc(0), m_oct(0) { }
Pitch::Pitch ( Integer  degree ) [inline]

Pitch constructor from scale degree.

Parameters:
degreeScale degree

Definition at line 74 of file Pitch.h.

References transpose().

                              : m_pc(0), m_acc(0), m_oct(0) { 
                transpose( degree, m_pc, m_acc, m_oct ); 
        }
Pitch::Pitch ( Integer  pitchClass,
Integer  accidental,
Integer  octave 
) [inline]

Pitch constructor from degree/accidental/octave.

Parameters:
pitchClassScale degree
accidentalAccidental
octaveOctave

Definition at line 82 of file Pitch.h.

: m_pc(pitchClass), m_acc(accidental), m_oct(octave) { }
Pitch::Pitch ( String  s )

Pitch constructor from string encoding.

Parameters:
sString containing pitch encoding

Definition at line 77 of file Pitch.cpp.

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

                     : m_pc(0), m_acc(0), m_oct(0) {
        If ((m_pc = isPitchClass(*s)) == -1)
                Return;

        Integer acc = 0;
        While ((acc = isAccidental(*++s)) != -3) {
                m_acc += acc;
        }

        If (*s == 0)
                Return;
        Else
                m_oct = atoi(s);
}
Pitch::Pitch ( Real  hz ) [inline]

Pitch constructor from frequency in Hz.

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

Definition at line 91 of file Pitch.h.

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

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

Member Function Documentation

Integer Pitch::accidental (  ) [inline]

The accidental of this pitch.

Definition at line 470 of file Pitch.h.

References Return.

Referenced by Accidental(), and hertz().

{ Return m_acc; }
Integer Pitch::degree ( Integer  pc,
Integer  acc,
Integer  oct 
) [inline]

Find the degree corresponding to pitch.

Parameters:
pcpitch class
accaccidental
octoctave
Returns:
The degree (index) of the specified pitch

Definition at line 117 of file Pitch.h.

References Return.

                                                                   {
                Return((pc + acc) + s_nDegrees * oct); 
        }
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 108 of file Pitch.h.

References Return.

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

                               {
                Return( degree(m_pc, m_acc, m_oct) ); 
        }
Real Pitch::hertz (  ) [inline]

The frequency in Hz of this pitch.

Definition at line 476 of file Pitch.h.

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

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

                           {
                Real R = s_HzReference;
                Real k = pitchClass() + accidental() - 9.0;
                Real o = octave() - 4.0;
                Return( R * Pow(2.0, o + k / Real(s_nDegrees) ) );
        }
Static Void Pitch::HzReference ( Real  ref ) [inline]

Set the reference frequency of the scale.

Definition at line 484 of file Pitch.h.

{ s_HzReference = ref; }
Static Real Pitch::HzReference (  ) [inline]

Get the reference frequency of the scale.

Definition at line 487 of file Pitch.h.

References Return.

Referenced by KeyToHertz().

{ Return( s_HzReference); }
Void Pitch::invert (  ) [inline]

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

Definition at line 175 of file Pitch.h.

References Mod(), and transpose().

                      {
                Integer p = Mod( m_pc + m_acc, s_nDegrees );
                p = Mod( s_nDegrees - p, s_nDegrees );
                transpose( p, m_pc = 0, m_acc = 0, m_oct );
        }
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 518 of file Pitch.h.

References Break, and Return.

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

                                           {
                switch (c) {
                case '#':           Return  1;  Break;  // sharp
                case 'S': case 's': Return  1;  Break;  // sharp
                case 'N': case 'n': Return  0;  Break;  // natural
                case 'B': case 'b':     Return -1;      Break;  // flat
                case 'F': case 'f':     Return -1;      Break;  // flat
                case 'X': case 'x':     Return  2;      Break;  // double-sharp
                case 'V': case 'v':     Return -2;      Break;  // double-flat
                default: Return -3;             Break; // may be an octave spec. with no accidental
                }
        }
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 501 of file Pitch.h.

References Break, and Return.

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

                                           {
                switch (c) {
                case 'C': case 'c': Return 0; Break;
                case 'D': case 'd': Return 2; Break;
                case 'E': case 'e': Return 4; Break;
                case 'F': case 'f': Return 5; Break;
                case 'G': case 'g': Return 7; Break;
                case 'A': case 'a': Return 9; Break;
                case 'B': case 'b': Return 11; Break;
                default: Return -1;
                }
        }
Integer Pitch::octave (  ) [inline]

The octave of this pitch.

Definition at line 473 of file Pitch.h.

References Return.

Referenced by hertz(), and Octave().

{ Return m_oct; }
Pitch::operator Integer (  ) [inline]

Definition at line 66 of file Pitch.h.

References degree(), and Return.

{ Return degree(); }
Pitch::operator Real (  ) [inline]

Definition at line 67 of file Pitch.h.

References hertz(), and Return.

{ Return hertz(); }
Bool Pitch::operator!= ( Const Pitch x ) [inline]

Pitch inequality operator.

Definition at line 197 of file Pitch.h.

References degree(), and Return.

                                              {
                Return degree() != x.degree();
        }
Bool Pitch::operator!= ( Const Integer x ) [inline]

Pitch inequality operator with Integer.

Definition at line 202 of file Pitch.h.

References degree(), and Return.

                                                {
                Return degree() != x;
        }
Bool Pitch::operator!= ( Const Real x ) [inline]

Pitch inequality operator with Real.

Definition at line 207 of file Pitch.h.

References hertz(), and Return.

                                             {
                Return hertz() != x;
        }
Pitch Pitch::operator% ( Const Pitch  x ) [inline]

Pitch modulo operator.

Definition at line 409 of file Pitch.h.

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

                                       {
                Integer d = Mod(degree(), x.degree());
                Return( d );
        }
Pitch Pitch::operator% ( Const Integer  x ) [inline]

Pitch modulo operator with Integer.

Definition at line 415 of file Pitch.h.

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

                                         {
                Integer d = Mod(degree(), x);
                Return( d );
        }
Pitch Pitch::operator% ( Const Real  x ) [inline]

Pitch modulo operator with Real.

Definition at line 421 of file Pitch.h.

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

                                      {
                Real hz = Mod(hertz(), x);
                Return( Pitch(hz) );
        }
Pitch Pitch::operator* ( Const Pitch x ) [inline]

Pitch multiplication operator.

Definition at line 378 of file Pitch.h.

References degree(), and Return.

                                        {
                Return( degree() * x.degree() );
        }
Pitch Pitch::operator* ( Const Integer  x ) [inline]

Pitch multiplication operator with Integer.

Definition at line 383 of file Pitch.h.

References degree(), and Return.

                                         {
                Return( degree() * x );
        }
Pitch Pitch::operator* ( Const Real  x ) [inline]

Pitch multiplication operator with Real.

Definition at line 388 of file Pitch.h.

References hertz(), and Return.

                                      {
                Return( hertz() * x );
        }
Pitch& Pitch::operator*= ( Const Pitch  x ) [inline]

Pitch multiply scale operator.

Definition at line 309 of file Pitch.h.

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

                                         {
                Integer d = degree() * x.degree();
                Return( *this = Pitch(d) );
        }
Pitch& Pitch::operator*= ( Const Integer  x ) [inline]

Pitch multiply scale operator with Integer.

Definition at line 315 of file Pitch.h.

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

                                           {
                Integer d = degree() * x;
                Return( *this = Pitch(d) );
        }
Pitch& Pitch::operator*= ( Const Real  x ) [inline]

Pitch multiply scale operator with Real.

Definition at line 321 of file Pitch.h.

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

                                        {
                Real hz = hertz() * x;
                Return( *this = Pitch(hz) );
        }
Pitch Pitch::operator+ ( Const Integer  x ) [inline]

Pitch addition operator with Integer.

Definition at line 351 of file Pitch.h.

References degree(), and Return.

                                         {
                Return( degree() + x );
        }
Pitch Pitch::operator+ ( Const Real  x ) [inline]

Pitch addition operator with Real.

Definition at line 356 of file Pitch.h.

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

                                      {
                Real hz = hertz() * x;
                Return( Pitch(hz) );
        }
Pitch Pitch::operator+ ( Const Pitch x ) [inline]

Pitch addition operator.

Definition at line 346 of file Pitch.h.

References degree(), and Return.

                                        {
                Return( degree() + x.degree() );
        }
Pitch& Pitch::operator+= ( Const Pitch  x ) [inline]

Pitch increment operator.

Definition at line 272 of file Pitch.h.

References Return, and transpose().

                                         {
                transpose( x.degree(), m_pc, m_acc, m_oct );
                Return( *this );
        }
Pitch& Pitch::operator+= ( Const Integer  x ) [inline]

Pitch increment operator with Integer.

Definition at line 278 of file Pitch.h.

References Return, and transpose().

                                           {
                transpose( x, m_pc, m_acc, m_oct );
                Return( *this );
        }
Pitch& Pitch::operator+= ( Const Real  x ) [inline]

Pitch increment operator with Real.

Definition at line 284 of file Pitch.h.

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

                                        {
                Real hz = hertz() + x;
                *this = Pitch( hz );
                Return( *this );
        }
Pitch Pitch::operator- ( Const Pitch x ) [inline]

Pitch subtraction operator.

Definition at line 362 of file Pitch.h.

References degree(), and Return.

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

Pitch subtraction operator with Real.

Definition at line 372 of file Pitch.h.

References hertz(), and Return.

                                      {
                Real hz = hertz() - x;
                Return( hz );
        }
Pitch Pitch::operator- ( Const Integer  x ) [inline]

Pitch subtraction operator with Integer.

Definition at line 367 of file Pitch.h.

References degree(), and Return.

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

Pitch decrement operator with Real.

Definition at line 303 of file Pitch.h.

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

                                        {
                Real hz = hertz() - x;
                Return( *this = Pitch( hz ) );
        }
Pitch& Pitch::operator-= ( Const Integer  x ) [inline]

Pitch decrement operator with Integer.

Definition at line 297 of file Pitch.h.

References Return, and transpose().

                                           {
                transpose( -x, m_pc, m_acc, m_oct );
                Return( *this );
        }
Pitch& Pitch::operator-= ( Const Pitch  x ) [inline]

Pitch decrement operator.

Definition at line 291 of file Pitch.h.

References Return, and transpose().

                                         {
                transpose( -x.degree(), m_pc, m_acc, m_oct );
                Return( *this );
        }
Pitch Pitch::operator/ ( Const Real  x ) [inline]

Pitch division operator with Real.

Definition at line 403 of file Pitch.h.

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

                                      {
                Real hz = hertz() / x;
                Return( Pitch(hz) );
        }
Pitch Pitch::operator/ ( Const Pitch x ) [inline]

Pitch division operator.

Definition at line 393 of file Pitch.h.

References degree(), and Return.

                                        {
                Return( degree() / x.degree() );
        }
Pitch Pitch::operator/ ( Const Integer  x ) [inline]

Pitch division operator with Integer.

Definition at line 398 of file Pitch.h.

References degree(), and Return.

                                         {
                Return( degree() / x );
        }
Pitch& Pitch::operator/= ( Const Pitch  x ) [inline]

Pitch divide scale operator.

Definition at line 327 of file Pitch.h.

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

                                         {
                Integer d = degree() / x.degree();
                Return( *this = Pitch(d) );
        }
Pitch& Pitch::operator/= ( Const Integer  x ) [inline]

Pitch divide scale operator with Integer.

Definition at line 333 of file Pitch.h.

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

                                           {
                Integer d = degree() / x;
                Return( *this = Pitch(d) );

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

Pitch divide scale operator with Real.

Definition at line 340 of file Pitch.h.

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

                                        {
                Real hz = hertz() / x;
                Return( *this = Pitch(hz) );
        }
Bool Pitch::operator< ( Const Integer x ) [inline]

Pitch < operator with Integer.

Definition at line 247 of file Pitch.h.

References degree(), and Return.

                                               {
                Return degree() < x;
        }
Bool Pitch::operator< ( Const Pitch x ) [inline]

Pitch < operator.

Definition at line 242 of file Pitch.h.

References degree(), and Return.

                                             {
                Return degree() < x.degree();
        }
Bool Pitch::operator< ( Const Real x ) [inline]

Pitch < operator with Real.

Definition at line 252 of file Pitch.h.

References hertz(), and Return.

                                            {
                Return hertz() < x;
        }
Bool Pitch::operator<= ( Const Pitch x ) [inline]

Pitch <= operator.

Definition at line 257 of file Pitch.h.

References degree(), and Return.

                                              {
                Return degree() <= x.degree();
        }
Bool Pitch::operator<= ( Const Integer x ) [inline]

Pitch <= operator with Integer.

Definition at line 262 of file Pitch.h.

References degree(), and Return.

                                                {
                Return degree() <= x;
        }
Bool Pitch::operator<= ( Const Real x ) [inline]

Pitch <= operator with Real.

Definition at line 267 of file Pitch.h.

References hertz(), and Return.

                                             {
                Return hertz() <= x;
        }
Bool Pitch::operator== ( Const Pitch x ) [inline]

Pitch equality operator.

Definition at line 182 of file Pitch.h.

References degree(), and Return.

                                              {
                Return degree() == x.degree();
        }
Bool Pitch::operator== ( Const Integer x ) [inline]

Pitch equality operator with Integer.

Definition at line 187 of file Pitch.h.

References degree(), and Return.

                                                {
                Return degree() == x;
        }
Bool Pitch::operator== ( Const Real x ) [inline]

Pitch equality operator with Real.

Definition at line 192 of file Pitch.h.

References hertz(), and Return.

                                             {
                Return hertz() == x;
        }
Bool Pitch::operator> ( Const Real x ) [inline]

Pitch > operator with Real.

Definition at line 237 of file Pitch.h.

References hertz(), and Return.

                                            {
                Return hertz() > x;
        }
Bool Pitch::operator> ( Const Integer x ) [inline]

Pitch > operator with Integer.

Definition at line 232 of file Pitch.h.

References degree(), and Return.

                                               {
                Return degree() > x;
        }
Bool Pitch::operator> ( Const Pitch x ) [inline]

Pitch > operator.

Definition at line 227 of file Pitch.h.

References degree(), and Return.

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

Pitch >= operator.

Definition at line 212 of file Pitch.h.

References degree(), and Return.

                                              {
                Return degree() >= x.degree();
        }
Bool Pitch::operator>= ( Const Integer x ) [inline]

Pitch >= operator with Integer.

Definition at line 217 of file Pitch.h.

References degree(), and Return.

                                                {
                Return degree() >= x;
        }
Bool Pitch::operator>= ( Const Real x ) [inline]

Pitch >= operator with Real.

Definition at line 222 of file Pitch.h.

References hertz(), and Return.

                                             {
                Return hertz() >= x;
        }
Integer Pitch::pianoKey ( Integer  pc,
Integer  acc,
Integer  oct 
) [inline]

Find the piano key corresponding to pitch.

Parameters:
pcpitch class
accaccidental
octoctave
Returns:
The piano key index of the specified pitch

Definition at line 132 of file Pitch.h.

References Return.

                                                                     {
                Return((pc + acc) + s_nDegrees * (oct - 1) + 3); 
        }
Integer Pitch::pianoKey (  ) [inline]

The piano key index.

Returns:
Piano key index of this Pitch

Definition at line 123 of file Pitch.h.

References Return.

                                 {
                Return( pianoKey(m_pc, m_acc, m_oct) ); 
        }
Integer Pitch::pitchClass (  ) [inline]

The pitch class of this pitch.

Definition at line 467 of file Pitch.h.

References Return.

Referenced by hertz(), and PitchClass().

{ Return m_pc; }
String Pitch::print ( String  s = 0 ) [inline]

Print pitch prefixed by string.

Parameters:
sString to prefix

Definition at line 428 of file Pitch.h.

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

Referenced by operator<<().

                                         {
                If (s)
                        cout << s;
                Character pc = s_pcNames[ m_pc ];
                Character acc;
                switch (m_acc) {
                case 0: acc = 0; Break;                 // natural
                case 1: acc = 's'; Break;               // sharp
                case -1: acc = 'b'; Break;              // flat
                case 2: acc = 'x'; Break;               // double-sharp
                case -2: acc = 'v'; Break;              // double-flat
                default: acc = 0; Break;                // natural
                }
                If (acc)
#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, "%c%c%d", pc, acc, m_oct);
#pragma warning(pop)
#else
                        sprintf(s_buf, "%c%c%d", pc, acc, m_oct);
#endif
                Else
#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, "%c%d", pc, m_oct);
#pragma warning(pop)
#else
                        sprintf(s_buf, "%c%d", pc, m_oct);
#endif
                Return s_buf;
        }
Static Void Pitch::SetDegrees ( Integer  ref ) [inline]

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

Definition at line 496 of file Pitch.h.

Referenced by SetDegrees().

{ 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 493 of file Pitch.h.

{ 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 490 of file Pitch.h.

{ 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:
xDegrees to transpose

Definition at line 167 of file Pitch.h.

References transpose().

                                          {
                Integer o = m_oct;
                transpose( x, m_pc, m_acc, m_oct );
                m_oct = o;
        }
Void Pitch::transpose ( Integer  x,
Integer pc,
Integer acc,
Integer oct 
) [inline]

Transpose pitch.

Parameters:
xNumber of degrees to transpose by
pcpitch class
accaccidental
octoctave
Returns:
The transposed Pitch

Definition at line 142 of file Pitch.h.

References Break, Else, If, and While.

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

                                                                           {
                pc += acc + x;  // add the pitch, its accidental and the transposition to get raw semitones
                acc = 0; // clear the accidental
                While ( pc >= s_nDegrees ) { pc = pc - s_nDegrees; oct++; }
                While ( pc < 0 ) { pc = pc + s_nDegrees; oct--; }
                // cvt. to diatonic
                switch (pc) {                   // adjust for enharmonic spelling
                case 0: Break;                                                                                                  // C
                case 1: If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // C# Db
                case 2: Break;                                                                                                  // D
                case 3: If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // D# Eb
                case 4: Break;                                                                                                  // E
                case 5: Break;                                                                                                  // F
                case 6: If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // F# Gb
                case 7: Break;                                                                                                  // G
                case 8: If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // G# Ab
                case 9: Break;                                                                                                  // A
                case 10:If (x>0) { pc--; acc++; } Else { pc++; acc--; } Break;  // A# Bb
                case 11: Break;                                                                                                 // B
                }
        }

Friends And Related Function Documentation

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

Definition at line 44 of file Pitch.h.

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

Definition at line 56 of file Pitch.h.

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

Definition at line 45 of file Pitch.h.

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

Definition at line 55 of file Pitch.h.

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

Definition at line 24 of file Pitch.cpp.

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

Definition at line 50 of file Pitch.h.

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

Definition at line 61 of file Pitch.h.

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

Definition at line 62 of file Pitch.h.

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

Definition at line 51 of file Pitch.h.

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

Definition at line 43 of file Pitch.h.

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

Definition at line 42 of file Pitch.h.

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

Definition at line 53 of file Pitch.h.

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

Definition at line 54 of file Pitch.h.

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

Definition at line 48 of file Pitch.h.

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

Definition at line 59 of file Pitch.h.

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

Definition at line 49 of file Pitch.h.

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

Definition at line 60 of file Pitch.h.

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

Definition at line 46 of file Pitch.h.

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

Definition at line 57 of file Pitch.h.

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

Definition at line 47 of file Pitch.h.

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

Definition at line 58 of file Pitch.h.

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

Definition at line 40 of file Pitch.cpp.

{
        //char buf[16];
        //cin >> buf;
        //p = Pitch(buf);
        //Return is;
        char c;
        cin >> c;
        If ((p.m_pc = p.isPitchClass(c)) == -1) {
                cin.unget();
                Return is;
        }

        Integer acc = 0;
        While (cin >> c && ((acc = p.isAccidental(c)) != -3)) {
                p.m_acc += acc;
        }

        If (!inRange(c, '0', '9')) {
                cin.unget();
                Return is;
        } Else {
                char buf[16];
                char* b = buf;
                Integer cnt = 0;
                cin.unget(); 
                While (!cin.eof() && cin >> c && isnumeric(c) && cnt++ < 16) {
//                      char y = cin.eof();
                        *b++ = c;
                }
                cin.unget();
                *b = '\0';
                p.m_oct = atoi(buf);
        }
        Return is;
}

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