- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Exponent::Music::CMusicMath Class Reference

List of all members.

## Detailed Description

Lots of calculations with musical relevance : ** ITS SCAL AS A CLASS! **.

Date:
  07/05/2005

Author:
  Paul Chana

Version:
  1.0.0 Initial version

Note:
  All contents of this source code are copyright 2005 Exp Digital Uk.
  This source file is covered by the licence conditions of the Infinity API. You should have recieved a copy
  with the source code. If you didnt, please refer to http://www.expdigital.co.uk All content is the Intellectual property of Exp Digital Uk.
  Certain sections of this code may come from other sources. They are credited where applicable.
  If you have comments, suggestions or bug reports please visit http://support.expdigital.co.uk

Id
  CMusicMath.hpp,v 1.4 2007/02/08 21:08:09 paul Exp

Definition at line 35 of file CMusicMath.hpp.

## Public Types

- enum ETempoDivision {
  e_sixtyFourBars = 0,
  e_thirtyTwoBars,
  e_sixteenBars,
  e_eightBars,
  e_fourBars,
  e_twoBars,
  e_oneBar,
  e_halfBar,
  e_quarterBar,
  e_eigthBar,
  e_sixteenthBar,
  e_thirtySecondBar,
  e_sixtyFourthBar,
  e_sixtyFourBarsTriplet,
  e_thirtyTwoBarsTriplet,
  e_sixteenBarsTriplet,
  e_eightBarsTriplet,
  e_fourBarsTriplet,
  e_twoBarsTriplet,
  e_oneBarTriplet,
  e_halfBarTriplet,
  e_quarterBarTriplet,
  e_eigthBarTriplet,
  e_sixteenthBarTriplet,
  e_thirtySecondBarTriplet,
  e_sixtyFourthBarTriplet,
  e_sixtyFourBarsDotted,
  e_thirtyTwoBarsDotted,
  e_sixteenBarsDotted,
  e_eightBarsDotted,
  e_fourBarsDotted,
  e_twoBarsDotted,
  e_oneBarDotted,
  e_halfBarDotted,
  e_quarterBarDotted,
  e_eigthBarDotted,
  e_sixteenthBarDotted,
  e_thirtySecondBarDotted,
  e_sixtyFourthBarDotted,
  e_numTempoDivisions
  }
    Enumeration of tempo divisions. More...

## Static Public Member Functions

- static void getADivisionString (CString &theString, const ETempoDivision tempoDivision)
- static double getBpmFromTime (const double length, const CTimeSignature &timeSignature, const long numberOfBeats=4)
- static long getClosestMidiNote (const double frequency)
- static ETempoDivision getClosestTempoDivisionToRateInHertz (const double bpm, const double frequency)
- static double getNewTempoPitchShift (const double shift, const double bpm)
- static double getNoteFrequency (const long note, const long octaveDetune, const long semiDetune, const long fineDetune)
- static double getNoteFrequency (const long note)
- static double getNumberOfSamples (const double sampleRate, const double lengthInSeconds)
- static double getPhase (const ETempoDivision tempoDivision)
- static double getRateInHertz (const double bpm, const ETempoDivision tempoDivision)
- static double getRateInMilliseconds (const double bpm, const ETempoDivision tempoDivision, const CTimeSignature &timeSignature)
- static double getSongPhasePosition (const ETempoDivision tempoDivision)
- static double getTempoNoteShift (const double originalBpm, const double newBpm)
- static double getTimeFromBpm (const double bpm, const CTimeSignature &timeSignature, const long numberOfBeats=4)
- static double getTimeStretch (const double originalBpm, const double newBpm)

## Static Public Attributes

- static const double CMUSIC_MATH_FREQUENCY []
- static const double CMUSIC_MATH_SONG_PHASE []
- static const double CMUSIC_MATH_SONG_POSITION []
- static const double CMUSIC_MATH_TIME []

## Private Types

- enum ETempoDivisionType {
  e_straight = 0,
  e_triplet,
  e_dotted
  }
    Different types of division, re swing. More...

## Static Private Member Functions

- static double convertValueToTempoDivisionType (const double value, const ETempoDivisionType type)
- static ETempoDivision getAdjustedTempoDivision (const ETempoDivision division, ETempoDivisionType &type)

## Static Private Attributes

- static const double CMUSIC_MATH_DOTTED_TIME
- static const CFrequencyTable CMUSIC_MATH_FREQUENCY_TABLE
- static const double CMUSIC_MATH_TRIPLET_TIME

## Classes

- class CFrequencyTable
    A class to calculate the midi/frequency table. More...

## Member Enumeration Documentation

enum Exponent::Music::CMusicMath::ETempoDivision

Enumeration of tempo divisions.

Enumerator:

  e_sixtyFourBars | 64 bar sync
  e_thirtyTwoBars | 32 bar sync
  e_sixteenBars | 16 bar sync
  e_eightBars | 8 bar sync
  e_fourBars | 4 bar sync
  e_twoBars | 2 bar sync
  e_oneBar | 1 bar sync
  e_halfBar | 1/2 bar sync
  e_quarterBar | 1/4 bar sync
  e_eigthBar | 1/8 bar sync
  e_sixteenthBar | 1/16 bar sync
  e_thirtySecondBar | 1/32 bar sync
  e_sixtyFourthBar | 1/64 bar sync
  e_sixtyFourBarsTriplet | 64T bar sync
  e_thirtyTwoBarsTriplet | 32T bar sync
  e_sixteenBarsTriplet | 16T bar sync
  e_eightBarsTriplet | 8T bar sync
  e_fourBarsTriplet | 4T bar sync
  e_twoBarsTriplet | 2T bar sync
  e_oneBarTriplet | 1T bar sync
  e_halfBarTriplet | 1/2T bar sync
  e_quarterBarTriplet | 1/4T bar sync
  e_eigthBarTriplet | 1/8T bar sync
  e_sixteenthBarTriplet | 1/16T bar sync
  e_thirtySecondBarTriplet | 1/32T bar sync
  e_sixtyFourthBarTriplet | 1/64T bar sync
  e_sixtyFourBarsDotted | 64. bar sync
  e_thirtyTwoBarsDotted | 32. bar sync
  e_sixteenBarsDotted | 16. bar sync
  e_eightBarsDotted | 8. bar sync
  e_fourBarsDotted | 4. bar sync
  e_twoBarsDotted | 2. bar sync
  e_oneBarDotted | 1. bar sync
  e_halfBarDotted | 1/2. bar sync
  e_quarterBarDotted | 1/4. bar sync
  e_eigthBarDotted | 1/8. bar sync
  e_sixteenthBarDotted | 1/16. bar sync
  e_thirtySecondBarDotted | 1/32. bar sync
  e_sixtyFourthBarDotted | 1/64. bar sync
  e_numTempoDivisions | Total number of tempo divisions

Definition at line 52 of file CMusicMath.hpp.

enum Exponent::Music::CMusicMath::ETempoDivisionType`[private]`

Different types of division, re swing.

Enumerator:

  e_straight | Straight time
  e_triplet | Triplet time
  e_dotted | Dotted time

Definition at line 242 of file CMusicMath.hpp.

## Member Function Documentation

static double Exponent::Music::CMusicMath::convertValueToTempoDivisionType | ( | const double | value,
|  | const ETempoDivisionType | type |
| ) |  |  | `[static, private]`

Convert a value to dotted or triplet time

Parameters:

  | value | The value to convert
  | type | The type of division to compute

Return values:

  | double | The converted value

static void Exponent::Music::CMusicMath::getADivisionString | ( | CString & | theString,
|  | const ETempoDivision | tempoDivision |
| ) |  |  | `[static]`

Get a division string

Parameters:

  | theString | The string that will be filled with the tempo division
  | tempoDivision | The tempo division

static ETempoDivision Exponent::Music::CMusicMath::getAdjustedTempoDivision | ( | const ETempoDivision | division,
|  | ETempoDivisionType & | type |
| ) |  |  | `[static, private]`

Get an adjusted tempo division -> in the range of stright time

Parameters:

  | division | The division to convert
  | type | The type of division to compute

Return values:

  | ETempoDivision | The adjusted tempo division in the range of stright time

static double Exponent::Music::CMusicMath::getBpmFromTime | ( | const double | length,
|  | const CTimeSignature & | timeSignature,
|  | const long | numberOfBeats = `4` |
| ) |  |  | `[static]`

Given a length (seconds) and time sig information what is the bpm

Parameters:

  | length | The length in seconds
  | timeSignature | The time signature
  | numberOfBeats | The number of beats in the section of music

Return values:

  | double | The bpm

static long Exponent::Music::CMusicMath::getClosestMidiNote | ( | const double | frequency | ) | `[static]`

Given a frequency what is the closest midi note

Parameters:

  | frequency | The frequency to convert

Return values:

  | long | The closest midi note to the frequency

static ETempoDivision Exponent::Music::CMusicMath::getClosestTempoDivisionToRateInHertz | ( | const double | bpm,
|  | const double | frequency |
| ) |  |  | `[static]`

Get the closest division for a given frequency and bpm

Parameters:

  | bpm | The beats per minute of the song
  | frequency | The frequency to convert to a division

Return values:

  | ETempoDivision | The closest tempo division

static double Exponent::Music::CMusicMath::getNewTempoPitchShift | ( | const double | shift,
|  | const double | bpm |
| ) |  |  | `[static]`

Given an original bpm and the amount shifted by, what is the new bpm

Parameters:

  | shift | The shift amount in semi tones
  | bpm | The original bpm

Return values:

  | double | The new bpm

static double Exponent::Music::CMusicMath::getNoteFrequency | ( | const long | note,
|  | const long | octaveDetune,
|  | const long | semiDetune,
|  | const long | fineDetune |
| ) |  |  | `[static]`

Get a detailed frequency

Parameters:

  | note | The midi note
  | octaveDetune | The number of octaves the note is detuned by
  | semiDetune | The number of semi tones the note is detuned by
  | fineDetune | The number of cents the note is detuned by

Return values:

  | double | The frequency, or 0.0 if error

static double Exponent::Music::CMusicMath::getNoteFrequency | ( | const long | note | ) | `[static]`

Get a frequency for a midi note

Parameters:

  | note | The midi note to get the frequency for

Return values:

  | double | The frequency, or 0.0 if index out of range

static double Exponent::Music::CMusicMath::getNumberOfSamples | ( | const double | sampleRate,
|  | const double | lengthInSeconds |
| ) |  |  | `[static]`

Get number of samples in a specified length (length in seconds

Parameters:

  | sampleRate | The number of samples per second
  | lengthInSeconds | The length of the buffer in seconds

Return values:

  | double | The number of samples in the specified length of time

static double Exponent::Music::CMusicMath::getPhase | ( | const ETempoDivision | tempoDivision | ) | `[static]`

Get a phase position for a given tempo division

Parameters:

  | tempoDivision | The tempo division

Return values:

  | double | The phase reset position

static double Exponent::Music::CMusicMath::getRateInHertz | ( | const double | bpm,
|  | const ETempoDivision | tempoDivision |
| ) |  |  | `[static]`

Get a rate in hertz for a given tempo division of the bpm

Parameters:

  | bpm | The beats per minute
  | tempoDivision | The requested tempo division

Return values:

  | The | rate in hertz required

static double Exponent::Music::CMusicMath::getRateInMilliseconds | ( | const double | bpm,
|  | const ETempoDivision | tempoDivision,
|  | const CTimeSignature & | timeSignature |
| ) |  |  | `[static]`

Get a rate in milliseconds for a given tempo division of the bpm

Parameters:

  | bpm | The beats per minute
  | tempoDivision | The requested tempo division
  | timeSignature | The time signature of the tune

Return values:

  | The | rate in milliseconds required

static double Exponent::Music::CMusicMath::getSongPhasePosition | ( | const ETempoDivision | tempoDivision | ) | `[static]`

Get a song phase postion for a given tempo division

Parameters:

  | tempoDivision | The tempo division

Return values:

  | double | The phase position

static double Exponent::Music::CMusicMath::getTempoNoteShift | ( | const double | originalBpm,
|  | const double | newBpm |
| ) |  |  | `[static]`

Given an original bpm and a desired bpm how much do you have to shift it by in semitones

Parameters:

  | originalBpm | The original Bpm
  | newBpm | The destination Bpm

Return values:

  | double | The shift in semi tones

static double Exponent::Music::CMusicMath::getTimeFromBpm | ( | const double | bpm,
|  | const CTimeSignature & | timeSignature,
|  | const long | numberOfBeats = `4` |
| ) |  |  | `[static]`

Given a bpm and time sig information what is the length

Parameters:

  | bpm | The bpm
  | timeSignature | The time signature
  | numberOfBeats | The number of beats in the section of music

Return values:

  | double | The length in seconds

static double Exponent::Music::CMusicMath::getTimeStretch | ( | const double | originalBpm,
|  | const double | newBpm |
| ) |  |  | `[static]`

To go from one bpm to antoher what is the timestretch required (%)

Parameters:

  | originalBpm | The original Bpm
  | newBpm | The destination Bpm

Return values:

  | double | The amount of time stretch required in %

## Member Data Documentation

const double Exponent::Music::CMusicMath::CMUSIC_MATH_DOTTED_TIME`[static, private]`

Dotted time multiplier

Definition at line 348 of file CMusicMath.hpp.

const double Exponent::Music::CMusicMath::CMUSIC_MATH_FREQUENCY[]`[static]`

Frequencies for tempo divisions

Definition at line 41 of file CMusicMath.hpp.

const CFrequencyTable Exponent::Music::CMusicMath::CMUSIC_MATH_FREQUENCY_TABLE`[static, private]`

The frequency table

Definition at line 345 of file CMusicMath.hpp.

const double Exponent::Music::CMusicMath::CMUSIC_MATH_SONG_PHASE[]`[static]`

Song phase for computing offset

Definition at line 43 of file CMusicMath.hpp.

const double Exponent::Music::CMusicMath::CMUSIC_MATH_SONG_POSITION[]`[static]`

Position modifier for song phase

Definition at line 44 of file CMusicMath.hpp.

const double Exponent::Music::CMusicMath::CMUSIC_MATH_TIME[]`[static]`

Timing information for tempo divisions

Definition at line 42 of file CMusicMath.hpp.

const double Exponent::Music::CMusicMath::CMUSIC_MATH_TRIPLET_TIME`[static, private]`

Triplet time multiplier

Definition at line 347 of file CMusicMath.hpp.