Lomse library. API documentation  0.30.0
FIntval Class Reference

#include <lomse_interval.h>

Detailed Description

Class FIntval represents an interval. Intervals are defined using the properties of FPitch representation: An interval is just the difference between the two FPitches.

Intervals can be added and substracted. For example, a perfect fifth minus a major third is a minor third (p5-M3 = m3)

Intervals greater than one octave can also be build directly. For example, a major 10th:

But can also be computed by adding octaves to simple intervals. For example, a major 10th is a major third plus one octave (M3+p8 = M10), thus:

Intervals have sign: positive intervals are ascending and negative ones are descending but, appart from the sign, all other properties do not change. For example:

// intv is a negative interval (minor 6th, descending). Thus, the following
// assertions are true:
assert(intv < 0);
assert(intv.is_descending() == true);
// But all other properties do not change by being descending:
assert( intv.get_number() == 3 );
assert( intv.get_type() == k_major );
assert( intv.get_num_semitones() == 5 );
assert( intv.get_code() == "M3" );

Macros for all the simple intervals are also defined, for convenience. They are named 'k_interval_xxxx', where 'xxxx' is the abbreviated name. See get_code().

FIntval(9, k_augmented) == FIntval(2, k_augmented) + k_interval_p8;
FIntval(9, k_augmented) == k_interval_a2 + k_interval_p8;

Public Member Functions

 FIntval (int number, EIntervalType type)
 
 FIntval (const string &code, bool fDescending=false)
 
 FIntval (int value)
 
 FIntval ()
 
 operator int ()
 
string get_code ()
 
int get_number ()
 
EIntervalType get_type ()
 
int get_num_semitones ()
 
bool is_descending ()
 
void make_descending ()
 
bool is_ascending ()
 
void make_ascending ()
 
bool operator== (FIntval intv)
 
bool operator!= (FIntval intv)
 
bool operator< (FIntval intv)
 
bool operator> (FIntval intv)
 
bool operator<= (FIntval intv)
 
bool operator>= (FIntval intv)
 
FIntval operator- (FIntval intv)
 
FIntval operator+ (FIntval intv)
 
FIntval operator-= (FIntval intv)
 
FIntval operator+= (FIntval intv)
 

Constructor & Destructor Documentation

◆ FIntval() [1/4]

FIntval::FIntval ( int  number,
EIntervalType  type 
)

Constructor for building an interval from its number and its type.

Parameters
numberThe interval number. Positive for ascending intervals or negative for descending intervals.
typeA value from enum EIntervalType.

Examples:

FInval(3, k_minor); //a third minor, ascending
FInval(9, k_augmented); //an augmented ninth, ascending
FInval(-2, k_major); //a major second, descending

◆ FIntval() [2/4]

FIntval::FIntval ( const string &  code,
bool  fDescending = false 
)

Constructor for building an interval from its code. See get_code().

Warning
This constructor is only valid for intervals up to one octave. The maximum allowed is "da8" (double augmented octave).

Examples:

FInval("m3"); //a third minor, ascending
FInval("a6"); //an augmented sixth, ascending
FIntval("m7", k_descending); //a minor seventh, descending

◆ FIntval() [3/4]

FIntval::FIntval ( int  value)
inline

Contructor for building an interval from an integer representing the interval value.

Warning
The interval value is not the interval number but an internal code that is returned when casting an FIntval object to an int.

◆ FIntval() [4/4]

FIntval::FIntval ( )

Default empty constructor. Builds an invalid, null interval.

Member Function Documentation

◆ get_code()

string FIntval::get_code ( )

Return string representing the interval code (its abbreviated name). Examples: "m2", "p4", "M3".

The code is the same for ascending and descending intervals. To check for a descending interval use is_descending() method.

The codes are formed by concatenating one or two characters with the interval number. The valid characters are as follows:

dd  - double diminished
d   - diminished
m   - minor
M   - Major
p   - perfect
a   - augmented
da  - double augmented

Thus:

'm2' is a minor 2nd
'p4' is a perfect fourth
'M3' is a major third
'da9' is a double augmented ninth
'p15' is a two octaves

Macros for all the simple intervals are also defined, for convenience. They are named 'k_interval_xxxx', where 'xxxx' is the code of the interval. For example:

k_interval_m2 == FIntval(2, k_minor) //minor 2nd
k_interval_p4 == FIntval(4, k_perfect) //perfect fourth
k_interval_M3 == FIntval(3, k_major) //major third
k_interval_da9 == FIntval(9, k_double_augmented) //double augmented ninth
k_interval_p8 == FIntval(8, k_perfect) //perfect octave

◆ get_num_semitones()

int FIntval::get_num_semitones ( )

Returns the number of semitones implied by this interval.

The numebr of semitones is always positive. It doesn't matter if the interval is ascending or descending. To check for a descending interval use is_descending() method.

◆ get_number()

int FIntval::get_number ( )

Returns the interval number: 1 for unison, 2 for second, 3 for third, ... , 8 for octave, 9 for ninth, ..., 15 for two octaves, and so on.

The number is the same for ascending and descending intervals. To check for a descending interval use is_descending() method.

◆ get_type()

EIntervalType FIntval::get_type ( )

Returns the interval type (diminished, major, etc.) as a value from enum EIntervalType.

The type is the same for ascending and descending intervals. To check for a descending interval use is_descending() method.

◆ is_ascending()

bool FIntval::is_ascending ( )
inline

Returns true if the interval is ascending or unison and false when it is descending.

◆ is_descending()

bool FIntval::is_descending ( )
inline

Returns true if the interval is descending and false when it is unison or ascending.

◆ make_ascending()

void FIntval::make_ascending ( )
inline

Transforms the interval in an ascending interval. If it is already ascending this method does nothing.

◆ make_descending()

void FIntval::make_descending ( )
inline

Transforms the interval in a descending interval. If it is already descending this method does nothing.

◆ operator int()

FIntval::operator int ( )
inline

Operator to cast to an int. Negative for descending intervals.

◆ operator!=()

bool FIntval::operator!= ( FIntval  intv)
inline

Comparison operators

◆ operator+()

FIntval FIntval::operator+ ( FIntval  intv)
inline

Add/substract operators

◆ operator+=()

FIntval FIntval::operator+= ( FIntval  intv)
inline

Add/substract operators

◆ operator-()

FIntval FIntval::operator- ( FIntval  intv)
inline

Add/substract operators

◆ operator-=()

FIntval FIntval::operator-= ( FIntval  intv)
inline

Add/substract operators

◆ operator<()

bool FIntval::operator< ( FIntval  intv)
inline

Comparison operators

◆ operator<=()

bool FIntval::operator<= ( FIntval  intv)
inline

Comparison operators

◆ operator==()

bool FIntval::operator== ( FIntval  intv)
inline

Comparison operators

◆ operator>()

bool FIntval::operator> ( FIntval  intv)
inline

Comparison operators

◆ operator>=()

bool FIntval::operator>= ( FIntval  intv)
inline

Comparison operators