Klang C++ 0.7.15
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Pitch

Language Guide / Units and Conversions

Pitch

klang::Pitch

Musical pitch as a MIDI note number.

Use Pitch for note values. Convert with -> Frequency to obtain the frequency in Hz. This example gives concert A. See Frequency for the reciprocal conversion.

Example

const param hz = Pitch(69) -> Frequency;

Control parameter (pitch) More...

#include <klang.h>

+ Inheritance diagram for klang::Pitch:

Public Member Functions

const char * text () const
 
const Pitch * operator-> ()
 
template<typename TYPE >
Pitch operator+ (TYPE in)
 
template<typename TYPE >
Pitch operator- (TYPE in)
 
template<typename TYPE >
Pitch operator* (TYPE in)
 
template<typename TYPE >
Pitch operator/ (TYPE in)
 
 param (constant in)
 
 param (const float initial=0.f)
 
 param (const signal &in)
 
 param (signal &in)
 
 param (Control &in)
 
template<typename SOURCE , std::enable_if_t<!std::is_arithmetic_v< std::decay_t< SOURCE > > &&!std::is_base_of_v< signal, std::decay_t< SOURCE > > &&!std::is_same_v< std::decay_t< SOURCE >, Control > &&std::is_convertible_v< SOURCE &&, const signal & >, int > = 0>
 param (SOURCE &&source)
 
param & operator+= (const increment &increment)
 
signal & operator+= (Output &in)
 Adds processed output of in to signal.
 
signal & operator+= (const signal &x)
 Add (mix) another signal to the signal.
 
signal & operator+= (float x)
 Add the specified amount to the signal.
 
signal & operator+= (double x)
 Add the specified amount to the signal.
 
signal & operator+= (int x)
 Add the specified amount to the signal.
 
const signal & operator<< (const signal &input)
 Feedback operator (prevents further processing of returned value).
 
signal & operator>> (signal &destination) const
 Stream operator (feedforward; allows further processing)
 
signal & operator-= (const signal &x)
 Subtract another signal from the signal.
 
signal & operator-= (float x)
 Subtract the specified amount from the signal.
 
signal & operator-= (double x)
 Subtract the specified amount from the signal.
 
signal & operator-= (int x)
 Subtract the specified amount from the signal.
 
signal & operator*= (const signal &x)
 Multiply (modulate) signal by another signal.
 
signal & operator*= (float x)
 Multiply signal by the specified amount.
 
signal & operator*= (double x)
 Multiply signal by the specified amount.
 
signal & operator*= (int x)
 Multiply signal by the specified amount.
 
signal & operator/= (const signal &x)
 Divide signal by another signal.
 
signal & operator/= (float x)
 Divide signal by the specified amount.
 
signal & operator/= (double x)
 Divide signal by the specified amount.
 
signal & operator/= (int x)
 Divide signal by the specified amount.
 
signal operator+ (float x) const
 Add two signals together.
 
signal operator+ (double x) const
 Return a copy of the signal offset by x.
 
signal operator+ (int x) const
 Return a copy of the signal offset by x.
 
relative operator+ () const
 Returns a copy of the signal to treat as a relative offset (e.g. for phase modulation).
 
signal operator- (float x) const
 Subtract one signal from another.
 
signal operator- (double x) const
 Return a copy of the signal offset by -x.
 
signal operator- (int x) const
 Return a copy of the signal offset by -x.
 
signal operator* (float x) const
 Multiply (modulate) two signals.
 
signal operator* (double x) const
 Return a copy of the signal scaled by x.
 
signal operator* (int x) const
 Return a copy of the signal scaled by x.
 
signal operator/ (float x) const
 Divide one signal by another.
 
signal operator/ (double x) const
 Return a copy of the signal divided by.
 
signal operator/ (int x) const
 Return a copy of the signal divided by x.
 
signal operator^ (float x) const
 Return a copy of the signal raised to the power of x.
 
signal operator^ (double x) const
 Return a copy of the signal raised to the power of x.
 
signal operator^ (int x) const
 Return a copy of the signal raised to the power of x.
 
 operator const float () const
 
 operator float & ()
 
bool isDenormal () const
 Check if the signal contains a denormal value.
 
int channels () const
 Returns the number of channels (1 = mono).
 
relative relative () const
 Returns a copy of the signal to treat as a relative offset (e.g. for phase modulation).
 

Public Attributes

float value
 

Static Public Attributes

static THREAD_LOCAL Conversion Frequency
 

Detailed Description

Definition at line 1690 of file klang.h.

Member Function Documentation

◆ channels()

int klang::signal::channels ( ) const
inlineinherited

Definition at line 1235 of file klang.h.

1235{ return 1; }

◆ isDenormal()

bool klang::signal::isDenormal ( ) const
inlineinherited

Definition at line 1229 of file klang.h.

1229 {
1230 const unsigned int bits = *(const unsigned int*)&value;
1231 return !(bits & 0x7F800000) && (bits & 0x007FFFFF);
1232 }
float value
Definition klang.h:1124

References klang::signal::value.

◆ operator const float()

klang::signal::operator const float ( ) const
inlineinherited

Definition at line 1225 of file klang.h.

1225{ return value; }

References klang::signal::value.

◆ operator float &()

klang::signal::operator float & ( )
inlineinherited

Definition at line 1226 of file klang.h.

1226{ return value; }

References klang::signal::value.

◆ operator*() [1/4]

template<typename TYPE >
Pitch klang::Pitch::operator* ( TYPE in)
inline

Definition at line 1714 of file klang.h.

1714{ return value * in; }

◆ operator*() [2/4]

signal klang::signal::operator* ( double x) const
inlineinherited

Definition at line 1205 of file klang.h.

1205{ return value * (float)x; }

References klang::signal::value.

◆ operator*() [3/4]

signal klang::signal::operator* ( float x) const
inlineinherited

Definition at line 1196 of file klang.h.

1196{ return value * x; }

References klang::signal::value.

◆ operator*() [4/4]

signal klang::signal::operator* ( int x) const
inlineinherited

Definition at line 1214 of file klang.h.

1214{ return value * (float)x; }

References klang::signal::value.

◆ operator*=() [1/4]

signal & klang::signal::operator*= ( const signal & x)
inlineinherited

Definition at line 1160 of file klang.h.

1160{ value *= x.value; return *this; }

References klang::signal::value.

◆ operator*=() [2/4]

signal & klang::signal::operator*= ( double x)
inlineinherited

Definition at line 1178 of file klang.h.

1178{ value *= (float)x; return *this; }

References klang::signal::value.

◆ operator*=() [3/4]

signal & klang::signal::operator*= ( float x)
inlineinherited

Definition at line 1169 of file klang.h.

1169{ value *= x; return *this; }

References klang::signal::value.

◆ operator*=() [4/4]

signal & klang::signal::operator*= ( int x)
inlineinherited

Definition at line 1187 of file klang.h.

1187{ value *= (float)x; return *this; }

References klang::signal::value.

◆ operator+() [1/5]

template<typename TYPE >
Pitch klang::Pitch::operator+ ( TYPE in)
inline

Definition at line 1712 of file klang.h.

1712{ return value + in; }

◆ operator+() [2/5]

relative klang::signal::operator+ ( ) const
inlineinherited

Definition at line 1251 of file klang.h.

1251{ return { value }; }

References klang::signal::value.

◆ operator+() [3/5]

signal klang::signal::operator+ ( double x) const
inlineinherited

Definition at line 1201 of file klang.h.

1201{ return value + (float)x; }

References klang::signal::value.

◆ operator+() [4/5]

signal klang::signal::operator+ ( float x) const
inlineinherited

Definition at line 1192 of file klang.h.

1192{ return value + x; }

References klang::signal::value.

◆ operator+() [5/5]

signal klang::signal::operator+ ( int x) const
inlineinherited

Definition at line 1210 of file klang.h.

1210{ return value + (float)x; }

References klang::signal::value.

◆ operator+=() [1/6]

param & klang::param::operator+= ( const increment & increment)
inlineinherited

Definition at line 1499 of file klang.h.

1499 {
1500 value += increment.amount;
1501 if (value >= increment.size)
1502 value -= increment.size;
1503 return *this;
1504 }

References klang::increment::amount, and klang::increment::size.

◆ operator+=() [2/6]

signal & klang::signal::operator+= ( const signal & x)
inlineinherited

Definition at line 1156 of file klang.h.

1156{ value += x.value; return *this; }

References klang::signal::value.

◆ operator+=() [3/6]

signal & klang::signal::operator+= ( double x)
inlineinherited

Definition at line 1174 of file klang.h.

1174{ value += (float)x; return *this; }

References klang::signal::value.

◆ operator+=() [4/6]

signal & klang::signal::operator+= ( float x)
inlineinherited

Definition at line 1165 of file klang.h.

1165{ value += x; return *this; }

References klang::signal::value.

◆ operator+=() [5/6]

signal & klang::signal::operator+= ( int x)
inlineinherited

Definition at line 1183 of file klang.h.

1183{ value += (float)x; return *this; }

References klang::signal::value.

◆ operator+=() [6/6]

signal & klang::signal::operator+= ( Output & in)
inlineinherited

Definition at line 3872 of file klang.h.

3872 { // e.g. out += osc;
3873 value += signal(in);
3874 return *this;
3875 }
signal(constant initial)
Create signal from a constant.
Definition klang.h:1127

◆ operator-() [1/4]

template<typename TYPE >
Pitch klang::Pitch::operator- ( TYPE in)
inline

Definition at line 1713 of file klang.h.

1713{ return value - in; }

◆ operator-() [2/4]

signal klang::signal::operator- ( double x) const
inlineinherited

Definition at line 1203 of file klang.h.

1203{ return value - (float)x; }

References klang::signal::value.

◆ operator-() [3/4]

signal klang::signal::operator- ( float x) const
inlineinherited

Definition at line 1194 of file klang.h.

1194{ return value - x; }

References klang::signal::value.

◆ operator-() [4/4]

signal klang::signal::operator- ( int x) const
inlineinherited

Definition at line 1212 of file klang.h.

1212{ return value - (float)x; }

References klang::signal::value.

◆ operator-=() [1/4]

signal & klang::signal::operator-= ( const signal & x)
inlineinherited

Definition at line 1158 of file klang.h.

1158{ value -= x.value; return *this; }

References klang::signal::value.

◆ operator-=() [2/4]

signal & klang::signal::operator-= ( double x)
inlineinherited

Definition at line 1176 of file klang.h.

1176{ value -= (float)x; return *this; }

References klang::signal::value.

◆ operator-=() [3/4]

signal & klang::signal::operator-= ( float x)
inlineinherited

Definition at line 1167 of file klang.h.

1167{ value -= x; return *this; }

References klang::signal::value.

◆ operator-=() [4/4]

signal & klang::signal::operator-= ( int x)
inlineinherited

Definition at line 1185 of file klang.h.

1185{ value -= (float)x; return *this; }

References klang::signal::value.

◆ operator->()

const Pitch * klang::Pitch::operator-> ( )
inline

Definition at line 1705 of file klang.h.

1705 {
1706 Frequency = 440.f * power(2.f, (value - 69.f) / 12.f);
1707 return this;
1708 }
constexpr power_t< BASE, EXP > power(BASE base, EXP exp)
Raise base to the power exp.
Definition klang.h:216
static THREAD_LOCAL Conversion Frequency
Definition klang.h:1710

References klang::power().

◆ operator/() [1/4]

template<typename TYPE >
Pitch klang::Pitch::operator/ ( TYPE in)
inline

Definition at line 1715 of file klang.h.

1715{ return value / in; }

◆ operator/() [2/4]

signal klang::signal::operator/ ( double x) const
inlineinherited

Definition at line 1207 of file klang.h.

1207{ return value / (float)x; }

References klang::signal::value.

◆ operator/() [3/4]

signal klang::signal::operator/ ( float x) const
inlineinherited

Definition at line 1198 of file klang.h.

1198{ return value / x; }

References klang::signal::value.

◆ operator/() [4/4]

signal klang::signal::operator/ ( int x) const
inlineinherited

Definition at line 1216 of file klang.h.

1216{ return value / (float)x; }

References klang::signal::value.

◆ operator/=() [1/4]

signal & klang::signal::operator/= ( const signal & x)
inlineinherited

Definition at line 1162 of file klang.h.

1162{ value /= x.value; return *this; }

References klang::signal::value.

◆ operator/=() [2/4]

signal & klang::signal::operator/= ( double x)
inlineinherited

Definition at line 1180 of file klang.h.

1180{ value /= (float)x; return *this; }

References klang::signal::value.

◆ operator/=() [3/4]

signal & klang::signal::operator/= ( float x)
inlineinherited

Definition at line 1171 of file klang.h.

1171{ value /= x; return *this; }

References klang::signal::value.

◆ operator/=() [4/4]

signal & klang::signal::operator/= ( int x)
inlineinherited

Definition at line 1189 of file klang.h.

1189{ value /= (float)x; return *this; }

References klang::signal::value.

◆ operator<<()

const signal & klang::signal::operator<< ( const signal & input)
inlineinherited

Definition at line 1139 of file klang.h.

1139 {
1140 value = input;
1141 return *this;
1142 }

References klang::signal::value.

◆ operator>>()

signal & klang::signal::operator>> ( signal & destination) const
inlineinherited

Definition at line 1145 of file klang.h.

1145 {
1146 destination.value = value;
1147 return destination;
1148 }

References klang::signal::value.

◆ operator^() [1/3]

signal klang::signal::operator^ ( double x) const
inlineinherited

Definition at line 1221 of file klang.h.

1221{ return power(value, x); }

References klang::power(), and klang::signal::value.

◆ operator^() [2/3]

signal klang::signal::operator^ ( float x) const
inlineinherited

Definition at line 1219 of file klang.h.

1219{ return power(value, x); }

References klang::power(), and klang::signal::value.

◆ operator^() [3/3]

signal klang::signal::operator^ ( int x) const
inlineinherited

Definition at line 1223 of file klang.h.

1223{ return power(value, x); }

References klang::power(), and klang::signal::value.

◆ param() [1/6]

klang::param::param ( const float initial = 0.f)
inline

Definition at line 1488 of file klang.h.

1488: signal(initial) {}

◆ param() [2/6]

klang::param::param ( const signal & in)
inline

Definition at line 1489 of file klang.h.

1489: signal(in) {}

◆ param() [3/6]

klang::param::param ( constant in)
inline

Definition at line 1487 of file klang.h.

1487: signal(in.f) {}

◆ param() [4/6]

klang::param::param ( Control & in)
inline

Definition at line 1491 of file klang.h.

1960: signal(in.value) {}

◆ param() [5/6]

klang::param::param ( signal & in)
inline

Definition at line 1490 of file klang.h.

1490: signal(in) {}

◆ param() [6/6]

template<typename SOURCE , std::enable_if_t<!std::is_arithmetic_v< std::decay_t< SOURCE > > &&!std::is_base_of_v< signal, std::decay_t< SOURCE > > &&!std::is_same_v< std::decay_t< SOURCE >, Control > &&std::is_convertible_v< SOURCE &&, const signal & >, int > = 0>
klang::param::param ( SOURCE && source)
inline

Definition at line 1496 of file klang.h.

1497 : signal(static_cast<const signal&>(std::forward<SOURCE>(source))) {}

◆ relative()

relative klang::signal::relative ( ) const
inlineinherited

Definition at line 1253 of file klang.h.

1253{ return { value }; }

References klang::signal::value.

◆ text()

const char * klang::Pitch::text ( ) const
inline

Definition at line 1698 of file klang.h.

1698 {
1699 THREAD_LOCAL static char buffer[32] = { 0 };
1700 const char* const notes[12] = { "C", "C#/Db", "D", "D#/Eb", "E", "F", "F#/Gb", "G", "G#/Ab", "A", "A#/Bb", "B" };
1701 snprintf(buffer, 32, "%s%d", notes[(int)value % 12], (int)value / 12);
1702 return buffer;
1703 }
klang::interleaved::buffer< 2 > buffer
Definition klang.h:5999

Member Data Documentation

◆ Frequency

THREAD_LOCAL Conversion klang::Pitch::Frequency
inlinestatic

Definition at line 1710 of file klang.h.

◆ value