Browse Source

Rework base DSP class

gh-pages
falkTX 10 years ago
parent
commit
4344309ed0
6 changed files with 198 additions and 185 deletions
  1. +3
    -46
      dgl/Base.hpp
  2. +1
    -0
      distrho/DistrhoPlugin.hpp
  3. +1
    -0
      distrho/DistrhoUI.hpp
  4. +15
    -59
      distrho/src/DistrhoDefines.h
  5. +64
    -0
      distrho/src/DistrhoPluginChecks.h
  6. +114
    -80
      distrho/src/DistrhoPluginInternal.hpp

+ 3
- 46
dgl/Base.hpp View File

@@ -17,42 +17,9 @@
#ifndef DGL_BASE_HPP_INCLUDED
#define DGL_BASE_HPP_INCLUDED

/* Compatibility with non-clang compilers */
#ifndef __has_feature
# define __has_feature(x) 0
#endif
#ifndef __has_extension
# define __has_extension __has_feature
#endif

/* Check OS */
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# define DGL_OS_WINDOWS 1
#elif defined(__APPLE__)
# define DGL_OS_MAC 1
#elif defined(__HAIKU__)
# define DGL_OS_HAIKU 1
#elif defined(__linux__) || defined(__linux)
# define DGL_OS_LINUX 1
#endif
#include "../distrho/src/DistrhoDefines.h"

/* Check for C++11 support */
#if defined(HAVE_CPP11_SUPPORT)
# define PROPER_CPP11_SUPPORT
#elif __cplusplus >= 201103L || (defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405) || __has_extension(cxx_noexcept)
# define PROPER_CPP11_SUPPORT
# if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407) || ! __has_extension(cxx_override_control)
# define override // gcc4.7+ only
# define final // gcc4.7+ only
# endif
#endif

#ifndef PROPER_CPP11_SUPPORT
# define noexcept throw()
# define override
# define final
# define nullptr (0)
#endif
// -----------------------------------------------------------------------

/* Define namespace */
#ifndef DGL_NAMESPACE
@@ -64,7 +31,7 @@
#define USE_NAMESPACE_DGL using namespace DGL_NAMESPACE;

/* GL includes */
#ifdef DGL_OS_MAC
#ifdef DISTRHO_OS_MAC
# include <OpenGL/gl.h>
#else
# include <GL/gl.h>
@@ -137,16 +104,6 @@ enum Modifier {
MODIFIER_SUPER = 1 << 3 /**< Mod4/Command/Windows key */
};

/*
* Cross-platform sleep function.
*/
void sleep(unsigned int secs);

/*
* Cross-platform msleep function.
*/
void msleep(unsigned int msecs);

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

END_NAMESPACE_DGL


+ 1
- 0
distrho/DistrhoPlugin.hpp View File

@@ -18,6 +18,7 @@
#define DISTRHO_PLUGIN_HPP_INCLUDED

#include "DistrhoUtils.hpp"
#include "src/DistrhoPluginChecks.h"

#include <cmath>



+ 1
- 0
distrho/DistrhoUI.hpp View File

@@ -18,6 +18,7 @@
#define DISTRHO_UI_HPP_INCLUDED

#include "DistrhoUtils.hpp"
#include "src/DistrhoPluginChecks.h"

#include "../dgl/Widget.hpp"



+ 15
- 59
distrho/src/DistrhoDefines.h View File

@@ -17,48 +17,6 @@
#ifndef DISTRHO_DEFINES_H_INCLUDED
#define DISTRHO_DEFINES_H_INCLUDED

#include "DistrhoPluginInfo.h"

#ifndef DISTRHO_PLUGIN_NAME
# error DISTRHO_PLUGIN_NAME undefined!
#endif

#ifndef DISTRHO_PLUGIN_HAS_UI
# error DISTRHO_PLUGIN_HAS_UI undefined!
#endif

#ifndef DISTRHO_PLUGIN_IS_SYNTH
# error DISTRHO_PLUGIN_IS_SYNTH undefined!
#endif

#ifndef DISTRHO_PLUGIN_NUM_INPUTS
# error DISTRHO_PLUGIN_NUM_INPUTS undefined!
#endif

#ifndef DISTRHO_PLUGIN_NUM_OUTPUTS
# error DISTRHO_PLUGIN_NUM_OUTPUTS undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_LATENCY
# error DISTRHO_PLUGIN_WANT_LATENCY undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_PROGRAMS
# error DISTRHO_PLUGIN_WANT_PROGRAMS undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_STATE
# error DISTRHO_PLUGIN_WANT_STATE undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_TIMEPOS
# error DISTRHO_PLUGIN_WANT_TIMEPOS undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
# define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0
#endif

/* Compatibility with non-clang compilers */
#ifndef __has_feature
# define __has_feature(x) 0
@@ -123,26 +81,26 @@
/* Define DISTRHO_DECLARE_NON_COPY_CLASS */
#ifdef DISTRHO_PROPER_CPP11_SUPPORT
# define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) \
private: \
ClassName(ClassName&) = delete; \
ClassName(const ClassName&) = delete; \
ClassName& operator=(ClassName&) = delete; \
private: \
ClassName(ClassName&) = delete; \
ClassName(const ClassName&) = delete; \
ClassName& operator=(ClassName&) = delete ; \
ClassName& operator=(const ClassName&) = delete;
#else
# define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) \
private: \
ClassName(ClassName&); \
ClassName(const ClassName&); \
ClassName& operator=(ClassName&); \
private: \
ClassName(ClassName&); \
ClassName(const ClassName&); \
ClassName& operator=(ClassName&); \
ClassName& operator=(const ClassName&);
#endif

/* Define DISTRHO_DECLARE_NON_COPY_STRUCT */
#ifdef DISTRHO_PROPER_CPP11_SUPPORT
# define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) \
StructName(StructName&) = delete; \
StructName(const StructName&) = delete; \
StructName& operator=(StructName&) = delete; \
StructName(StructName&) = delete; \
StructName(const StructName&) = delete; \
StructName& operator=(StructName&) = delete; \
StructName& operator=(const StructName&) = delete;
#else
# define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName)
@@ -150,14 +108,14 @@ private: \

/* Define DISTRHO_PREVENT_HEAP_ALLOCATION */
#ifdef DISTRHO_PROPER_CPP11_SUPPORT
# define DISTRHO_PREVENT_HEAP_ALLOCATION \
private: \
# define DISTRHO_PREVENT_HEAP_ALLOCATION \
private: \
static void* operator new(size_t) = delete; \
static void operator delete(void*) = delete;
#else
# define DISTRHO_PREVENT_HEAP_ALLOCATION \
private: \
static void* operator new(size_t); \
private: \
static void* operator new(size_t); \
static void operator delete(void*);
#endif

@@ -175,8 +133,6 @@ private: \
# define USE_NAMESPACE_DISTRHO
#endif

#define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI"

/* Useful typedefs */
typedef unsigned char uchar;
typedef unsigned long int ulong;


+ 64
- 0
distrho/src/DistrhoPluginChecks.h View File

@@ -0,0 +1,64 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef DISTRHO_PLUGIN_CHECKS_H_INCLUDED
#define DISTRHO_PLUGIN_CHECKS_H_INCLUDED

#include "DistrhoPluginInfo.h"

#ifndef DISTRHO_PLUGIN_NAME
# error DISTRHO_PLUGIN_NAME undefined!
#endif

#ifndef DISTRHO_PLUGIN_HAS_UI
# error DISTRHO_PLUGIN_HAS_UI undefined!
#endif

#ifndef DISTRHO_PLUGIN_IS_SYNTH
# error DISTRHO_PLUGIN_IS_SYNTH undefined!
#endif

#ifndef DISTRHO_PLUGIN_NUM_INPUTS
# error DISTRHO_PLUGIN_NUM_INPUTS undefined!
#endif

#ifndef DISTRHO_PLUGIN_NUM_OUTPUTS
# error DISTRHO_PLUGIN_NUM_OUTPUTS undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_LATENCY
# error DISTRHO_PLUGIN_WANT_LATENCY undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_PROGRAMS
# error DISTRHO_PLUGIN_WANT_PROGRAMS undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_STATE
# error DISTRHO_PLUGIN_WANT_STATE undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_TIMEPOS
# error DISTRHO_PLUGIN_WANT_TIMEPOS undefined!
#endif

#ifndef DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
# define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0
#endif

#define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI"

#endif // DISTRHO_PLUGIN_CHECKS_H_INCLUDED

+ 114
- 80
distrho/src/DistrhoPluginInternal.hpp View File

@@ -77,11 +77,11 @@ struct Plugin::PrivateData {
bufferSize(d_lastBufferSize),
sampleRate(d_lastSampleRate)
{
assert(bufferSize != 0);
assert(sampleRate != 0.0);
DISTRHO_SAFE_ASSERT(bufferSize != 0);
DISTRHO_SAFE_ASSERT(sampleRate != 0.0);
}

~PrivateData()
~PrivateData() noexcept
{
if (parameters != nullptr)
{
@@ -117,10 +117,8 @@ public:
: fPlugin(createPlugin()),
fData((fPlugin != nullptr) ? fPlugin->pData : nullptr)
{
assert(fPlugin != nullptr);

if (fPlugin == nullptr)
return;
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,);

for (uint32_t i=0, count=fData->parameterCount; i < count; ++i)
fPlugin->d_initParameter(i, fData->parameters[i]);
@@ -145,32 +143,44 @@ public:

const char* getName() const noexcept
{
return (fPlugin != nullptr) ? fPlugin->d_getName() : "";
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, "");

return fPlugin->d_getName();
}

const char* getLabel() const noexcept
{
return (fPlugin != nullptr) ? fPlugin->d_getLabel() : "";
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, "");

return fPlugin->d_getLabel();
}

const char* getMaker() const noexcept
{
return (fPlugin != nullptr) ? fPlugin->d_getMaker() : "";
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, "");

return fPlugin->d_getMaker();
}

const char* getLicense() const noexcept
{
return (fPlugin != nullptr) ? fPlugin->d_getLicense() : "";
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, "");

return fPlugin->d_getLicense();
}

uint32_t getVersion() const noexcept
{
return (fPlugin != nullptr) ? fPlugin->d_getVersion() : 1000;
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, 0);

return fPlugin->d_getVersion();
}

long getUniqueId() const noexcept
{
return (fPlugin != nullptr) ? fPlugin->d_getUniqueId() : 0;
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, 0);

return fPlugin->d_getUniqueId();
}

void* getInstancePointer() const noexcept
@@ -183,19 +193,24 @@ public:
#if DISTRHO_PLUGIN_WANT_LATENCY
uint32_t getLatency() const noexcept
{
return (fData != nullptr) ? fData->latency : 0;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr, 0);

return fData->latency;
}
#endif

uint32_t getParameterCount() const noexcept
{
return (fData != nullptr) ? fData->parameterCount : 0;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr, 0);

return fData->parameterCount;
}

uint32_t getParameterHints(const uint32_t index) const noexcept
{
assert(index < fData->parameterCount);
return (fData != nullptr && index < fData->parameterCount) ? fData->parameters[index].hints : 0x0;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, 0x0);

return fData->parameters[index].hints;
}

bool isParameterOutput(const uint32_t index) const noexcept
@@ -205,100 +220,117 @@ public:

const d_string& getParameterName(const uint32_t index) const noexcept
{
assert(index < fData->parameterCount);
return (fData != nullptr && index < fData->parameterCount) ? fData->parameters[index].name : sFallbackString;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, sFallbackString);

return fData->parameters[index].name;
}

const d_string& getParameterSymbol(const uint32_t index) const noexcept
{
assert(index < fData->parameterCount);
return (fData != nullptr && index < fData->parameterCount) ? fData->parameters[index].symbol : sFallbackString;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, sFallbackString);

return fData->parameters[index].symbol;
}

const d_string& getParameterUnit(const uint32_t index) const noexcept
{
assert(index < fData->parameterCount);
return (fData != nullptr && index < fData->parameterCount) ? fData->parameters[index].unit : sFallbackString;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, sFallbackString);

return fData->parameters[index].unit;
}

const ParameterRanges& getParameterRanges(const uint32_t index) const noexcept
{
assert(index < fData->parameterCount);
return (fData != nullptr && index < fData->parameterCount) ? fData->parameters[index].ranges : sFallbackRanges;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, sFallbackRanges);

return fData->parameters[index].ranges;
}

float getParameterValue(const uint32_t index) const noexcept
float getParameterValue(const uint32_t index) const
{
assert(index < fData->parameterCount);
return (fPlugin != nullptr && index < fData->parameterCount) ? fPlugin->d_getParameterValue(index) : 0.0f;
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, 0.0f);
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, 0.0f);

return fPlugin->d_getParameterValue(index);
}

void setParameterValue(const uint32_t index, const float value)
{
assert(index < fData->parameterCount);
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount,);

if (fPlugin != nullptr && index < fData->parameterCount)
fPlugin->d_setParameterValue(index, value);
fPlugin->d_setParameterValue(index, value);
}

#if DISTRHO_PLUGIN_WANT_PROGRAMS
uint32_t getProgramCount() const noexcept
{
return (fData != nullptr) ? fData->programCount : 0;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr, 0);

return fData->programCount;
}

const d_string& getProgramName(const uint32_t index) const noexcept
{
assert(index < fData->programCount);
return (fData != nullptr && index < fData->programCount) ? fData->programNames[index] : sFallbackString;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->programCount, sFallbackString);

return fData->programNames[index];
}

void setProgram(const uint32_t index)
{
assert(index < fData->programCount);
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->programCount,);

if (fPlugin != nullptr && index < fData->programCount)
fPlugin->d_setProgram(index);
fPlugin->d_setProgram(index);
}
#endif

#if DISTRHO_PLUGIN_WANT_STATE
bool wantsStateKey(const char* const key) const noexcept
uint32_t getStateCount() const noexcept
{
for (uint32_t i=0; i < fData->stateCount; ++i)
{
if (fData->stateKeys[i] == key)
return true;
}
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr, 0);

return false;
return fData->stateCount;
}

uint32_t getStateCount() const noexcept
const d_string& getStateKey(const uint32_t index) const noexcept
{
return fData != nullptr ? fData->stateCount : 0;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->stateCount, sFallbackString);

return fData->stateKeys[index];
}

const d_string& getStateKey(const uint32_t index) const noexcept
void setState(const char* const key, const char* const value)
{
assert(index < fData->stateCount);
return (fData != nullptr && index < fData->stateCount) ? fData->stateKeys[index] : sFallbackString;
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->stateCount,);
DISTRHO_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
DISTRHO_SAFE_ASSERT_RETURN(value != nullptr,);

fPlugin->d_setState(key, value);
}

void setState(const char* const key, const char* const value)
bool wantStateKey(const char* const key) const noexcept
{
assert(key != nullptr && value != nullptr);
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr, false);
DISTRHO_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', false);

if (fPlugin != nullptr && key != nullptr && value != nullptr)
fPlugin->d_setState(key, value);
for (uint32_t i=0; i < fData->stateCount; ++i)
{
if (fData->stateKeys[i] == key)
return true;
}

return false;
}
#endif

#if DISTRHO_PLUGIN_WANT_TIMEPOS
void setTimePos(const TimePos& timePos)
void setTimePos(const TimePos& timePos) noexcept
{
if (fData != nullptr)
std::memcpy(&fData->timePos, &timePos, sizeof(TimePos));
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,);

std::memcpy(&fData->timePos, &timePos, sizeof(TimePos));
}
#endif

@@ -306,44 +338,47 @@ public:

void activate()
{
if (fPlugin != nullptr)
fPlugin->d_activate();
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);

fPlugin->d_activate();
}

void deactivate()
{
if (fPlugin != nullptr)
fPlugin->d_deactivate();
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);

fPlugin->d_deactivate();
}

#if DISTRHO_PLUGIN_IS_SYNTH
void run(float** const inputs, float** const outputs, const uint32_t frames, const MidiEvent* const midiEvents, const uint32_t midiEventCount)
{
if (fPlugin != nullptr)
fPlugin->d_run(inputs, outputs, frames, midiEvents, midiEventCount);
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);

fPlugin->d_run(inputs, outputs, frames, midiEvents, midiEventCount);
}
#else
void run(float** const inputs, float** const outputs, const uint32_t frames)
{
if (fPlugin != nullptr)
fPlugin->d_run(inputs, outputs, frames);
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);

fPlugin->d_run(inputs, outputs, frames);
}
#endif
// -------------------------------------------------------------------

void setBufferSize(const uint32_t bufferSize, bool doCallback = false)
{
assert(bufferSize >= 2);
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
DISTRHO_SAFE_ASSERT(bufferSize >= 2);

if (fData != nullptr)
{
if (doCallback && fData->bufferSize == bufferSize)
doCallback = false;
if (fData->bufferSize == bufferSize)
return;

fData->bufferSize = bufferSize;
}
fData->bufferSize = bufferSize;

if (fPlugin != nullptr && doCallback)
if (doCallback)
{
fPlugin->d_deactivate();
fPlugin->d_bufferSizeChanged(bufferSize);
@@ -353,17 +388,16 @@ public:

void setSampleRate(const double sampleRate, bool doCallback = false)
{
assert(sampleRate > 0.0);
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
DISTRHO_SAFE_ASSERT(sampleRate > 0.0);

if (fData != nullptr)
{
if (doCallback && fData->sampleRate == sampleRate)
doCallback = false;
if (fData->sampleRate == sampleRate)
return;

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

if (fPlugin != nullptr && doCallback)
if (doCallback)
{
fPlugin->d_deactivate();
fPlugin->d_sampleRateChanged(sampleRate);


Loading…
Cancel
Save