Browse Source

distrho changes from Carla

gh-pages
falkTX 10 years ago
parent
commit
b10ef44a1f
4 changed files with 81 additions and 8 deletions
  1. +74
    -1
      distrho/DistrhoUtils.hpp
  2. +2
    -2
      distrho/src/DistrhoPluginInternal.hpp
  3. +2
    -2
      distrho/src/DistrhoUI.cpp
  4. +3
    -3
      distrho/src/DistrhoUIInternal.hpp

+ 74
- 1
distrho/DistrhoUtils.hpp View File

@@ -24,6 +24,9 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>


#include <cmath>
#include <limits>

#ifdef DISTRHO_PROPER_CPP11_SUPPORT #ifdef DISTRHO_PROPER_CPP11_SUPPORT
# include <cstdint> # include <cstdint>
#else #else
@@ -46,18 +49,28 @@ inline float round(float __x)
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// misc functions // misc functions


/*
* Return a 64-bit number from 4 8-bit numbers.
*/
static inline static inline
int64_t d_cconst(const int a, const int b, const int c, const int d) noexcept
int64_t d_cconst(const uint8_t a, const uint8_t b, const uint8_t c, const uint8_t d) noexcept
{ {
return (a << 24) | (b << 16) | (c << 8) | (d << 0); return (a << 24) | (b << 16) | (c << 8) | (d << 0);
} }


/*
* Dummy function.
*/
static inline static inline
void d_pass() noexcept {} void d_pass() noexcept {}


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// string print functions // string print functions


/*
* Print a string to stdout with newline (gray color).
* Does nothing if DEBUG is not defined.
*/
#ifndef DEBUG #ifndef DEBUG
# define d_debug(...) # define d_debug(...)
#else #else
@@ -75,6 +88,9 @@ void d_debug(const char* const fmt, ...) noexcept
} }
#endif #endif


/*
* Print a string to stdout with newline.
*/
static inline static inline
void d_stdout(const char* const fmt, ...) noexcept void d_stdout(const char* const fmt, ...) noexcept
{ {
@@ -87,6 +103,9 @@ void d_stdout(const char* const fmt, ...) noexcept
} catch (...) {} } catch (...) {}
} }


/*
* Print a string to stderr with newline.
*/
static inline static inline
void d_stderr(const char* const fmt, ...) noexcept void d_stderr(const char* const fmt, ...) noexcept
{ {
@@ -99,6 +118,9 @@ void d_stderr(const char* const fmt, ...) noexcept
} catch (...) {} } catch (...) {}
} }


/*
* Print a string to stderr with newline (red color).
*/
static inline static inline
void d_stderr2(const char* const fmt, ...) noexcept void d_stderr2(const char* const fmt, ...) noexcept
{ {
@@ -112,18 +134,69 @@ void d_stderr2(const char* const fmt, ...) noexcept
} catch (...) {} } catch (...) {}
} }


/*
* Print a safe assertion error message.
*/
static inline static inline
void d_safe_assert(const char* const assertion, const char* const file, const int line) noexcept void d_safe_assert(const char* const assertion, const char* const file, const int line) noexcept
{ {
d_stderr2("assertion failure: \"%s\" in file %s, line %i", assertion, file, line); d_stderr2("assertion failure: \"%s\" in file %s, line %i", assertion, file, line);
} }


/*
* Print a safe exception error message.
*/
static inline static inline
void d_safe_exception(const char* const exception, const char* const file, const int line) noexcept void d_safe_exception(const char* const exception, const char* const file, const int line) noexcept
{ {
d_stderr2("exception caught: \"%s\" in file %s, line %i", exception, file, line); d_stderr2("exception caught: \"%s\" in file %s, line %i", exception, file, line);
} }


// -----------------------------------------------------------------------
// math functions

/*
* Safely compare two floating point numbers.
* Returns true if they match.
*/
template<typename T>
static inline
bool d_isEqual(const T& v1, const T& v2)
{
return std::abs(v1-v2) < std::numeric_limits<T>::epsilon();
}

/*
* Safely compare two floating point numbers.
* Returns true if they don't match.
*/
template<typename T>
static inline
bool d_isNotEqual(const T& v1, const T& v2)
{
return std::abs(v1-v2) >= std::numeric_limits<T>::epsilon();
}

/*
* Safely check if a floating point number is zero.
*/
template<typename T>
static inline
bool d_isZero(const T& value)
{
return std::abs(value) < std::numeric_limits<T>::epsilon();
}

/*
* Safely check if a floating point number is not zero.
*/
template<typename T>
static inline
bool d_isNotZero(const T& value)
{
return std::abs(value) >= std::numeric_limits<T>::epsilon();
}

// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


#endif // DISTRHO_UTILS_HPP_INCLUDED #endif // DISTRHO_UTILS_HPP_INCLUDED

+ 2
- 2
distrho/src/DistrhoPluginInternal.hpp View File

@@ -83,7 +83,7 @@ struct Plugin::PrivateData {
sampleRate(d_lastSampleRate) sampleRate(d_lastSampleRate)
{ {
DISTRHO_SAFE_ASSERT(bufferSize != 0); DISTRHO_SAFE_ASSERT(bufferSize != 0);
DISTRHO_SAFE_ASSERT(sampleRate != 0.0);
DISTRHO_SAFE_ASSERT(d_isNotZero(sampleRate));
} }


~PrivateData() noexcept ~PrivateData() noexcept
@@ -433,7 +433,7 @@ public:
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,); DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
DISTRHO_SAFE_ASSERT(sampleRate > 0.0); DISTRHO_SAFE_ASSERT(sampleRate > 0.0);


if (fData->sampleRate == sampleRate)
if (d_isEqual(fData->sampleRate, sampleRate))
return; return;


fData->sampleRate = sampleRate; fData->sampleRate = sampleRate;


+ 2
- 2
distrho/src/DistrhoUI.cpp View File

@@ -96,8 +96,8 @@ void UI::d_uiReshape(uint width, uint height)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glOrtho(0, width, height, 0, 0.0f, 1.0f);
glViewport(0, 0, width, height);
glOrtho(0.0, static_cast<GLdouble>(width), static_cast<GLdouble>(height), 0.0, 0.0, 1.0);
glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
} }


+ 3
- 3
distrho/src/DistrhoUIInternal.hpp View File

@@ -75,7 +75,7 @@ struct UI::PrivateData {
setSizeCallbackFunc(nullptr), setSizeCallbackFunc(nullptr),
ptr(nullptr) ptr(nullptr)
{ {
DISTRHO_SAFE_ASSERT(sampleRate != 0.0);
DISTRHO_SAFE_ASSERT(d_isNotZero(sampleRate));


#if defined(DISTRHO_PLUGIN_TARGET_DSSI) || defined(DISTRHO_PLUGIN_TARGET_LV2) #if defined(DISTRHO_PLUGIN_TARGET_DSSI) || defined(DISTRHO_PLUGIN_TARGET_LV2)
parameterOffset += DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS; parameterOffset += DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS;
@@ -331,7 +331,7 @@ public:
glWindow.setTitle(uiTitle); glWindow.setTitle(uiTitle);
} }


void setWindowTransientWinId(const intptr_t winId)
void setWindowTransientWinId(const uintptr_t winId)
{ {
glWindow.setTransientWinId(winId); glWindow.setTransientWinId(winId);
} }
@@ -351,7 +351,7 @@ public:
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);
DISTRHO_SAFE_ASSERT(sampleRate > 0.0); DISTRHO_SAFE_ASSERT(sampleRate > 0.0);


if (fData->sampleRate == sampleRate)
if (d_isEqual(fData->sampleRate, sampleRate))
return; return;


fData->sampleRate = sampleRate; fData->sampleRate = sampleRate;


Loading…
Cancel
Save