Browse Source

Fix the rest of the code for -Weffc++

tags/1.9.4
falkTX 10 years ago
parent
commit
017b87f811
6 changed files with 204 additions and 176 deletions
  1. +1
    -0
      source/Makefile.mk
  2. +3
    -3
      source/modules/native-plugins/Makefile
  3. +71
    -61
      source/modules/native-plugins/zynaddsubfx-fx.cpp
  4. +45
    -58
      source/modules/native-plugins/zynaddsubfx-synth.cpp
  5. +73
    -43
      source/plugin/carla-native-lv2.cpp
  6. +11
    -11
      source/utils/LinkedList.hpp

+ 1
- 0
source/Makefile.mk View File

@@ -120,6 +120,7 @@ CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
ifeq ($(LINUX),true) ifeq ($(LINUX),true)
CFLAGS += -isystem /opt/kxstudio/include CFLAGS += -isystem /opt/kxstudio/include
CXXFLAGS += -isystem /opt/kxstudio/include CXXFLAGS += -isystem /opt/kxstudio/include
CXXFLAGS += -isystem /opt/kxstudio/include/ntk
endif endif
ifeq ($(MACOS),true) ifeq ($(MACOS),true)
CFLAGS += -isystem /opt/kxstudio/include CFLAGS += -isystem /opt/kxstudio/include


+ 3
- 3
source/modules/native-plugins/Makefile View File

@@ -25,7 +25,7 @@ endif
# Flags for ZynAddSubFX # Flags for ZynAddSubFX


ifeq ($(HAVE_ZYN_DEPS),true) ifeq ($(HAVE_ZYN_DEPS),true)
ZYN_CXX_FLAGS = $(BUILD_CXX_FLAGS)
ZYN_CXX_FLAGS = $(BUILD_CXX_FLAGS) -isystem zynaddsubfx
ZYN_CXX_FLAGS += $(shell pkg-config --cflags fftw3 mxml zlib) ZYN_CXX_FLAGS += $(shell pkg-config --cflags fftw3 mxml zlib)
ifneq ($(MACOS),true) ifneq ($(MACOS),true)
ZYN_CXX_FLAGS += -DHAVE_SCHEDULER ZYN_CXX_FLAGS += -DHAVE_SCHEDULER
@@ -168,10 +168,10 @@ zynaddsubfx-%.cpp.o: zynaddsubfx-%.cpp $(CXXDEPS) $(ZYN_UI_FILES_H)
$(CXX) $< $(ZYN_CXX_FLAGS) -c -o $@ $(CXX) $< $(ZYN_CXX_FLAGS) -c -o $@


zynaddsubfx-src.cpp.o: zynaddsubfx-src.cpp $(ZYN_UI_FILES_H) zynaddsubfx-src.cpp.o: zynaddsubfx-src.cpp $(ZYN_UI_FILES_H)
$(CXX) $< $(ZYN_CXX_FLAGS) -c -o $@
$(CXX) $< $(ZYN_CXX_FLAGS) -w -c -o $@


zynaddsubfx-ui.cpp.o: zynaddsubfx-ui.cpp $(ZYN_UI_FILES_H) $(ZYN_UI_FILES_CPP) zynaddsubfx-ui.cpp.o: zynaddsubfx-ui.cpp $(ZYN_UI_FILES_H) $(ZYN_UI_FILES_CPP)
$(CXX) $< $(ZYN_CXX_FLAGS) -c -o $@
$(CXX) $< $(ZYN_CXX_FLAGS) -w -c -o $@


zynaddsubfx/UI/%.cpp: zynaddsubfx/UI/%.fl zynaddsubfx/UI/%.cpp: zynaddsubfx/UI/%.fl
ntk-fluid -c -o zynaddsubfx/UI/$*.cpp -h zynaddsubfx/UI/$*.h $< ntk-fluid -c -o zynaddsubfx/UI/$*.cpp -h zynaddsubfx/UI/$*.h $<


+ 71
- 61
source/modules/native-plugins/zynaddsubfx-fx.cpp View File

@@ -16,14 +16,15 @@
*/ */


#include "CarlaNative.hpp" #include "CarlaNative.hpp"
#include "CarlaMathUtils.hpp"


#include "zynaddsubfx/Effects/Alienwah.h"
#include "zynaddsubfx/Effects/Chorus.h"
#include "zynaddsubfx/Effects/Distorsion.h"
#include "zynaddsubfx/Effects/DynamicFilter.h"
#include "zynaddsubfx/Effects/Echo.h"
#include "zynaddsubfx/Effects/Phaser.h"
#include "zynaddsubfx/Effects/Reverb.h"
#include "Effects/Alienwah.h"
#include "Effects/Chorus.h"
#include "Effects/Distorsion.h"
#include "Effects/DynamicFilter.h"
#include "Effects/Echo.h"
#include "Effects/Phaser.h"
#include "Effects/Reverb.h"


#include "juce_audio_basics.h" #include "juce_audio_basics.h"
using juce::FloatVectorOperations; using juce::FloatVectorOperations;
@@ -40,9 +41,10 @@ protected:
fEffect(nullptr), fEffect(nullptr),
efxoutl(nullptr), efxoutl(nullptr),
efxoutr(nullptr), efxoutr(nullptr),
fFirstInit(true)
leakDetector_FxAbstractPlugin()
{ {
const uint32_t bufferSize(getBufferSize());
const int bufferSize(static_cast<int>(getBufferSize()));

efxoutl = new float[bufferSize]; efxoutl = new float[bufferSize];
efxoutr = new float[bufferSize]; efxoutr = new float[bufferSize];


@@ -81,7 +83,7 @@ protected:


float getParameterValue(const uint32_t index) const final float getParameterValue(const uint32_t index) const final
{ {
return fEffect->getpar(index+2);
return static_cast<float>(fEffect->getpar(static_cast<int>(index+2)));
} }


// ------------------------------------------------------------------- // -------------------------------------------------------------------
@@ -97,22 +99,14 @@ protected:


void setParameterValue(const uint32_t index, const float value) final void setParameterValue(const uint32_t index, const float value) final
{ {
fFirstInit = false;
fEffect->changepar(index+2, value);
fEffect->changepar(static_cast<int>(index+2), static_cast<uchar>(carla_fixValue(0.0f, 127.0f, value)));
} }


void setMidiProgram(const uint8_t, const uint32_t, const uint32_t program) final void setMidiProgram(const uint8_t, const uint32_t, const uint32_t program) final
{ {
fFirstInit = false;
fEffect->setpreset(program);

const float volume(float(fEffect->getpar(0))/127.0f);
hostSetVolume(volume);

const unsigned char pan(fEffect->getpar(1));
const float panning(float(pan)/63.5f-1.0f);
hostSetPanning(panning);
fEffect->setpreset(static_cast<uchar>(program));


// reset volume and pan
fEffect->changepar(0, 127); fEffect->changepar(0, 127);
fEffect->changepar(1, 64); fEffect->changepar(1, 64);
} }
@@ -123,20 +117,26 @@ protected:
void activate() final void activate() final
{ {
fEffect->cleanup(); fEffect->cleanup();

if (fFirstInit)
{
fFirstInit = false;
hostSetDryWet(0.5f);
}
} }


void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) final void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) final
{ {
const int iframes(static_cast<int>(frames));

if (outBuffer[0] != inBuffer[0])
FloatVectorOperations::copyWithMultiply(outBuffer[0], inBuffer[0], 0.5f, iframes);
else
FloatVectorOperations::multiply(outBuffer[0], 0.5f, iframes);

if (outBuffer[1] != inBuffer[1])
FloatVectorOperations::copyWithMultiply(outBuffer[1], inBuffer[1], 0.5f, iframes);
else
FloatVectorOperations::multiply(outBuffer[1], 0.5f, iframes);

fEffect->out(Stereo<float*>(inBuffer[0], inBuffer[1])); fEffect->out(Stereo<float*>(inBuffer[0], inBuffer[1]));


FloatVectorOperations::copy(outBuffer[0], efxoutl, frames);
FloatVectorOperations::copy(outBuffer[1], efxoutr, frames);
FloatVectorOperations::addWithMultiply(outBuffer[0], efxoutl, 0.5f, iframes);
FloatVectorOperations::addWithMultiply(outBuffer[1], efxoutr, 0.5f, iframes);
} }


// ------------------------------------------------------------------- // -------------------------------------------------------------------
@@ -144,35 +144,37 @@ protected:


void bufferSizeChanged(const uint32_t bufferSize) final void bufferSizeChanged(const uint32_t bufferSize) final
{ {
const int ibufferSize(static_cast<int>(getBufferSize()));

delete[] efxoutl; delete[] efxoutl;
delete[] efxoutr; delete[] efxoutr;
efxoutl = new float[bufferSize]; efxoutl = new float[bufferSize];
efxoutr = new float[bufferSize]; efxoutr = new float[bufferSize];
FloatVectorOperations::clear(efxoutl, bufferSize);
FloatVectorOperations::clear(efxoutr, bufferSize);
FloatVectorOperations::clear(efxoutl, ibufferSize);
FloatVectorOperations::clear(efxoutr, ibufferSize);


doReinit(bufferSize, getSampleRate());
doReinit(getSampleRate(), bufferSize);
} }


void sampleRateChanged(const double sampleRate) final void sampleRateChanged(const double sampleRate) final
{ {
doReinit(getBufferSize(), sampleRate);
doReinit(sampleRate, getBufferSize());
} }


void doReinit(const uint32_t bufferSize, const double sampleRate)
void doReinit(const double sampleRate, const uint32_t bufferSize)
{ {
float params[fParamCount];
uchar params[fParamCount];


for (uint32_t i=0; i < fParamCount; ++i)
for (int i=0, count=static_cast<int>(fParamCount); i<count; ++i)
params[i] = fEffect->getpar(i+2); params[i] = fEffect->getpar(i+2);


reinit(bufferSize, sampleRate);
reinit(static_cast<uint>(sampleRate), static_cast<int>(bufferSize));


for (uint32_t i=0; i < fParamCount; ++i)
for (int i=0, count=static_cast<int>(fParamCount); i<count; ++i)
fEffect->changepar(i+2, params[i]); fEffect->changepar(i+2, params[i]);
} }


virtual void reinit(const uint32_t bufferSize, const double sampleRate) = 0;
virtual void reinit(const uint sampleRate, const int bufferSize) = 0;


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


@@ -182,7 +184,8 @@ protected:
Effect* fEffect; Effect* fEffect;
float* efxoutl; float* efxoutl;
float* efxoutr; float* efxoutr;
bool fFirstInit;

CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FxAbstractPlugin)
}; };


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -191,9 +194,10 @@ class FxAlienWahPlugin : public FxAbstractPlugin
{ {
public: public:
FxAlienWahPlugin(const NativeHostDescriptor* const host) FxAlienWahPlugin(const NativeHostDescriptor* const host)
: FxAbstractPlugin(host, 11, 4)
: FxAbstractPlugin(host, 11, 4),
leakDetector_FxAlienWahPlugin()
{ {
fEffect = new Alienwah(false, efxoutl, efxoutr, getSampleRate(), getBufferSize());
fEffect = new Alienwah(false, efxoutl, efxoutr, static_cast<uint>(getSampleRate()), static_cast<int>(getBufferSize()));
} }


protected: protected:
@@ -320,7 +324,7 @@ protected:


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


void reinit(const uint32_t bufferSize, const double sampleRate)
void reinit(const uint sampleRate, const int bufferSize) override
{ {
delete fEffect; delete fEffect;
fEffect = new Alienwah(false, efxoutl, efxoutr, sampleRate, bufferSize); fEffect = new Alienwah(false, efxoutl, efxoutr, sampleRate, bufferSize);
@@ -336,9 +340,10 @@ class FxChorusPlugin : public FxAbstractPlugin
{ {
public: public:
FxChorusPlugin(const NativeHostDescriptor* const host) FxChorusPlugin(const NativeHostDescriptor* const host)
: FxAbstractPlugin(host, 12, 10)
: FxAbstractPlugin(host, 12, 10),
leakDetector_FxChorusPlugin()
{ {
fEffect = new Chorus(false, efxoutl, efxoutr, getSampleRate(), getBufferSize());
fEffect = new Chorus(false, efxoutl, efxoutr, static_cast<uint>(getSampleRate()), static_cast<int>(getBufferSize()));
} }


protected: protected:
@@ -489,7 +494,7 @@ protected:


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


void reinit(const uint32_t bufferSize, const double sampleRate)
void reinit(const uint sampleRate, const int bufferSize) override
{ {
delete fEffect; delete fEffect;
fEffect = new Chorus(false, efxoutl, efxoutr, sampleRate, bufferSize); fEffect = new Chorus(false, efxoutl, efxoutr, sampleRate, bufferSize);
@@ -505,9 +510,10 @@ class FxDistortionPlugin : public FxAbstractPlugin
{ {
public: public:
FxDistortionPlugin(const NativeHostDescriptor* const host) FxDistortionPlugin(const NativeHostDescriptor* const host)
: FxAbstractPlugin(host, 11, 6)
: FxAbstractPlugin(host, 11, 6),
leakDetector_FxDistortionPlugin()
{ {
fEffect = new Distorsion(false, efxoutl, efxoutr, getSampleRate(), getBufferSize());
fEffect = new Distorsion(false, efxoutl, efxoutr, static_cast<uint>(getSampleRate()), static_cast<int>(getBufferSize()));
} }


protected: protected:
@@ -666,7 +672,7 @@ protected:


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


void reinit(const uint32_t bufferSize, const double sampleRate)
void reinit(const uint sampleRate, const int bufferSize) override
{ {
delete fEffect; delete fEffect;
fEffect = new Distorsion(false, efxoutl, efxoutr, sampleRate, bufferSize); fEffect = new Distorsion(false, efxoutl, efxoutr, sampleRate, bufferSize);
@@ -682,9 +688,10 @@ class FxDynamicFilterPlugin : public FxAbstractPlugin
{ {
public: public:
FxDynamicFilterPlugin(const NativeHostDescriptor* const host) FxDynamicFilterPlugin(const NativeHostDescriptor* const host)
: FxAbstractPlugin(host, 10, 5)
: FxAbstractPlugin(host, 10, 5),
leakDetector_FxDynamicFilterPlugin()
{ {
fEffect = new DynamicFilter(false, efxoutl, efxoutr, getSampleRate(), getBufferSize());
fEffect = new DynamicFilter(false, efxoutl, efxoutr, static_cast<uint>(getSampleRate()), static_cast<int>(getBufferSize()));
} }


protected: protected:
@@ -809,7 +816,7 @@ protected:


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


void reinit(const uint32_t bufferSize, const double sampleRate)
void reinit(const uint sampleRate, const int bufferSize) override
{ {
delete fEffect; delete fEffect;
fEffect = new DynamicFilter(false, efxoutl, efxoutr, sampleRate, bufferSize); fEffect = new DynamicFilter(false, efxoutl, efxoutr, sampleRate, bufferSize);
@@ -825,9 +832,10 @@ class FxEchoPlugin : public FxAbstractPlugin
{ {
public: public:
FxEchoPlugin(const NativeHostDescriptor* const host) FxEchoPlugin(const NativeHostDescriptor* const host)
: FxAbstractPlugin(host, 7, 9)
: FxAbstractPlugin(host, 7, 9),
leakDetector_FxEchoPlugin()
{ {
fEffect = new Echo(false, efxoutl, efxoutr, getSampleRate(), getBufferSize());
fEffect = new Echo(false, efxoutl, efxoutr, static_cast<uint>(getSampleRate()), static_cast<int>(getBufferSize()));
} }


protected: protected:
@@ -940,7 +948,7 @@ protected:


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


void reinit(const uint32_t bufferSize, const double sampleRate)
void reinit(const uint sampleRate, const int bufferSize) override
{ {
delete fEffect; delete fEffect;
fEffect = new Echo(false, efxoutl, efxoutr, sampleRate, bufferSize); fEffect = new Echo(false, efxoutl, efxoutr, sampleRate, bufferSize);
@@ -956,9 +964,10 @@ class FxPhaserPlugin : public FxAbstractPlugin
{ {
public: public:
FxPhaserPlugin(const NativeHostDescriptor* const host) FxPhaserPlugin(const NativeHostDescriptor* const host)
: FxAbstractPlugin(host, 15, 12)
: FxAbstractPlugin(host, 15, 12),
leakDetector_FxPhaserPlugin()
{ {
fEffect = new Phaser(false, efxoutl, efxoutr, getSampleRate(), getBufferSize());
fEffect = new Phaser(false, efxoutl, efxoutr, static_cast<uint>(getSampleRate()), static_cast<int>(getBufferSize()));
} }


protected: protected:
@@ -1132,7 +1141,7 @@ protected:


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


void reinit(const uint32_t bufferSize, const double sampleRate)
void reinit(const uint sampleRate, const int bufferSize) override
{ {
delete fEffect; delete fEffect;
fEffect = new Phaser(false, efxoutl, efxoutr, sampleRate, bufferSize); fEffect = new Phaser(false, efxoutl, efxoutr, sampleRate, bufferSize);
@@ -1148,9 +1157,10 @@ class FxReverbPlugin : public FxAbstractPlugin
{ {
public: public:
FxReverbPlugin(const NativeHostDescriptor* const host) FxReverbPlugin(const NativeHostDescriptor* const host)
: FxAbstractPlugin(host, 13, 13)
: FxAbstractPlugin(host, 13, 13),
leakDetector_FxReverbPlugin()
{ {
fEffect = new Reverb(false, efxoutl, efxoutr, getSampleRate(), getBufferSize());
fEffect = new Reverb(false, efxoutl, efxoutr, static_cast<uint>(getSampleRate()), static_cast<int>(getBufferSize()));
} }


protected: protected:
@@ -1310,7 +1320,7 @@ protected:


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


void reinit(const uint32_t bufferSize, const double sampleRate)
void reinit(const uint sampleRate, const int bufferSize) override
{ {
delete fEffect; delete fEffect;
fEffect = new Reverb(false, efxoutl, efxoutr, sampleRate, bufferSize); fEffect = new Reverb(false, efxoutl, efxoutr, sampleRate, bufferSize);


+ 45
- 58
source/modules/native-plugins/zynaddsubfx-synth.cpp View File

@@ -22,10 +22,10 @@


#include "CarlaMathUtils.hpp" #include "CarlaMathUtils.hpp"


#include "zynaddsubfx/DSP/FFTwrapper.h"
#include "zynaddsubfx/Misc/Master.h"
#include "zynaddsubfx/Misc/Part.h"
#include "zynaddsubfx/Misc/Util.h"
#include "DSP/FFTwrapper.h"
#include "Misc/Master.h"
#include "Misc/Part.h"
#include "Misc/Util.h"


#ifdef WANT_ZYNADDSUBFX_UI #ifdef WANT_ZYNADDSUBFX_UI
# ifdef override # ifdef override
@@ -33,8 +33,8 @@
# undef override # undef override
# endif # endif


# include "zynaddsubfx/UI/common.H"
# include "zynaddsubfx/UI/MasterUI.h"
# include "UI/common.H"
# include "UI/MasterUI.h"
# include <FL/Fl_Shared_Image.H> # include <FL/Fl_Shared_Image.H>
# include <FL/Fl_Tiled_Image.H> # include <FL/Fl_Tiled_Image.H>
# include <FL/Fl_Theme.H> # include <FL/Fl_Theme.H>
@@ -77,9 +77,9 @@ class ZynAddSubFxPrograms
{ {
public: public:
ZynAddSubFxPrograms() ZynAddSubFxPrograms()
: fInitiated(false)
{
}
: fInitiated(false),
fRetProgram({0, 0, nullptr}),
fPrograms() {}


~ZynAddSubFxPrograms() ~ZynAddSubFxPrograms()
{ {
@@ -112,7 +112,7 @@ public:
// refresh banks // refresh banks
master.bank.rescanforbanks(); master.bank.rescanforbanks();


for (uint32_t i=0, size = master.bank.banks.size(); i < size; ++i)
for (uint32_t i=0, size=static_cast<uint32_t>(master.bank.banks.size()); i<size; ++i)
{ {
if (master.bank.banks[i].dir.empty()) if (master.bank.banks[i].dir.empty())
continue; continue;
@@ -165,12 +165,12 @@ public:
} }
} }


uint32_t count()
uint32_t count() const noexcept
{ {
return fPrograms.count();
return static_cast<uint32_t>(fPrograms.count());
} }


const NativeMidiProgram* getInfo(const uint32_t index)
const NativeMidiProgram* getInfo(const uint32_t index) const noexcept
{ {
if (index >= fPrograms.count()) if (index >= fPrograms.count())
return nullptr; return nullptr;
@@ -191,12 +191,12 @@ private:
uint32_t prog; uint32_t prog;
const char* name; const char* name;


ProgramInfo(uint32_t bank_, uint32_t prog_, const char* name_)
ProgramInfo(uint32_t bank_, uint32_t prog_, const char* name_) noexcept
: bank(bank_), : bank(bank_),
prog(prog_), prog(prog_),
name(carla_strdup(name_)) {}
name(carla_strdup_safe(name_)) {}


~ProgramInfo()
~ProgramInfo() noexcept
{ {
if (name != nullptr) if (name != nullptr)
{ {
@@ -215,9 +215,10 @@ private:
}; };


bool fInitiated; bool fInitiated;
NativeMidiProgram fRetProgram;
mutable NativeMidiProgram fRetProgram;
LinkedList<const ProgramInfo*> fPrograms; LinkedList<const ProgramInfo*> fPrograms;


CARLA_PREVENT_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPY_CLASS(ZynAddSubFxPrograms) CARLA_DECLARE_NON_COPY_CLASS(ZynAddSubFxPrograms)
}; };


@@ -292,8 +293,8 @@ public:
} }


synth = new SYNTH_T(); synth = new SYNTH_T();
synth->buffersize = host->get_buffer_size(host->handle);
synth->samplerate = host->get_sample_rate(host->handle);
synth->buffersize = static_cast<int>(host->get_buffer_size(host->handle));
synth->samplerate = static_cast<uint>(host->get_sample_rate(host->handle));


if (synth->buffersize > 32) if (synth->buffersize > 32)
synth->buffersize = 32; synth->buffersize = 32;
@@ -302,14 +303,14 @@ public:


config.init(); config.init();
config.cfg.SoundBufferSize = synth->buffersize; config.cfg.SoundBufferSize = synth->buffersize;
config.cfg.SampleRate = synth->samplerate;
config.cfg.SampleRate = static_cast<int>(synth->samplerate);
config.cfg.GzipCompression = 0; config.cfg.GzipCompression = 0;


sprng(std::time(nullptr));
sprng(static_cast<prng_t>(std::time(nullptr)));


denormalkillbuf = new float[synth->buffersize]; denormalkillbuf = new float[synth->buffersize];
for (int i=0; i < synth->buffersize; ++i) for (int i=0; i < synth->buffersize; ++i)
denormalkillbuf[i] = (RND - 0.5f) * 1e-16;
denormalkillbuf[i] = (RND - 0.5f) * 1e-16f;


Master::getInstance(); Master::getInstance();
} }
@@ -326,6 +327,7 @@ public:
private: private:
int fCount; int fCount;


CARLA_PREVENT_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPY_CLASS(ZynAddSubFxInstanceCount) CARLA_DECLARE_NON_COPY_CLASS(ZynAddSubFxInstanceCount)
}; };


@@ -536,6 +538,9 @@ private:
volatile uint8_t fNextChannel; volatile uint8_t fNextChannel;
volatile uint32_t fNextBank; volatile uint32_t fNextBank;
volatile uint32_t fNextProgram; volatile uint32_t fNextProgram;

CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPY_CLASS(ZynAddSubFxThread)
}; };


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -546,9 +551,10 @@ public:
ZynAddSubFxPlugin(const NativeHostDescriptor* const host) ZynAddSubFxPlugin(const NativeHostDescriptor* const host)
: NativePluginClass(host), : NativePluginClass(host),
fMaster(new Master()), fMaster(new Master()),
fSampleRate(getSampleRate()),
fSampleRate(static_cast<uint>(getSampleRate())),
fIsActive(false), fIsActive(false),
fThread(fMaster, host)
fThread(fMaster, host),
leakDetector_ZynAddSubFxPlugin()
{ {
fThread.startThread(); fThread.startThread();


@@ -556,11 +562,6 @@ public:
fMaster->partonoff(i, 1); fMaster->partonoff(i, 1);


sPrograms.init(); sPrograms.init();

#if 0
// create instance if needed
getGlobalMutex();
#endif
} }


~ZynAddSubFxPlugin() override ~ZynAddSubFxPlugin() override
@@ -643,46 +644,42 @@ protected:
{ {
if (pthread_mutex_trylock(&fMaster->mutex) != 0) if (pthread_mutex_trylock(&fMaster->mutex) != 0)
{ {
FloatVectorOperations::clear(outBuffer[0], frames);
FloatVectorOperations::clear(outBuffer[1], frames);
FloatVectorOperations::clear(outBuffer[0], static_cast<int>(frames));
FloatVectorOperations::clear(outBuffer[1], static_cast<int>(frames));
return; return;
} }


#if 0
const CarlaMutexLocker csm(getGlobalMutex());
#endif

for (uint32_t i=0; i < midiEventCount; ++i) for (uint32_t i=0; i < midiEventCount; ++i)
{ {
const NativeMidiEvent* const midiEvent(&midiEvents[i]); const NativeMidiEvent* const midiEvent(&midiEvents[i]);


const uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent->data); const uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent->data);
const uint8_t channel = MIDI_GET_CHANNEL_FROM_DATA(midiEvent->data);
const char channel = MIDI_GET_CHANNEL_FROM_DATA(midiEvent->data);


if (MIDI_IS_STATUS_NOTE_OFF(status)) if (MIDI_IS_STATUS_NOTE_OFF(status))
{ {
const uint8_t note = midiEvent->data[1];
const char note = static_cast<char>(midiEvent->data[1]);


fMaster->noteOff(channel, note); fMaster->noteOff(channel, note);
} }
else if (MIDI_IS_STATUS_NOTE_ON(status)) else if (MIDI_IS_STATUS_NOTE_ON(status))
{ {
const uint8_t note = midiEvent->data[1];
const uint8_t velo = midiEvent->data[2];
const char note = static_cast<char>(midiEvent->data[1]);
const char velo = static_cast<char>(midiEvent->data[2]);


fMaster->noteOn(channel, note, velo); fMaster->noteOn(channel, note, velo);
} }
else if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status)) else if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status))
{ {
const uint8_t note = midiEvent->data[1];
const uint8_t pressure = midiEvent->data[2];
const char note = static_cast<char>(midiEvent->data[1]);
const char pressure = static_cast<char>(midiEvent->data[2]);


fMaster->polyphonicAftertouch(channel, note, pressure); fMaster->polyphonicAftertouch(channel, note, pressure);
} }
else if (MIDI_IS_STATUS_CONTROL_CHANGE(status)) else if (MIDI_IS_STATUS_CONTROL_CHANGE(status))
{ {
const uint8_t control = midiEvent->data[1];
const uint8_t value = midiEvent->data[2];
const int control = midiEvent->data[1];
const int value = midiEvent->data[2];


fMaster->setController(channel, control, value); fMaster->setController(channel, control, value);
} }
@@ -729,7 +726,7 @@ protected:
void setState(const char* const data) override void setState(const char* const data) override
{ {
fThread.stopLoadProgramLater(); fThread.stopLoadProgramLater();
fMaster->putalldata((char*)data, 0);
fMaster->putalldata(const_cast<char*>(data), 0);
fMaster->applyparameters(true); fMaster->applyparameters(true);
} }


@@ -747,7 +744,7 @@ protected:


void sampleRateChanged(const double sampleRate) final void sampleRateChanged(const double sampleRate) final
{ {
fSampleRate = sampleRate;
fSampleRate = static_cast<uint>(sampleRate);
deleteMaster(); deleteMaster();
sInstanceCount.maybeReinit(getHostHandle()); sInstanceCount.maybeReinit(getHostHandle());
initMaster(); initMaster();
@@ -784,22 +781,12 @@ protected:
// ------------------------------------------------------------------- // -------------------------------------------------------------------


private: private:
Master* fMaster;
unsigned fSampleRate;
bool fIsActive;
Master* fMaster;
uint fSampleRate;
bool fIsActive;


ZynAddSubFxThread fThread; ZynAddSubFxThread fThread;


#if 0
// -------------------------------------------------------------------

static CarlaMutex& getGlobalMutex() noexcept
{
static CarlaMutex m;
return m;
}
#endif

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


public: public:


+ 73
- 43
source/plugin/carla-native-lv2.cpp View File

@@ -39,27 +39,67 @@ using juce::FloatVectorOperations;


#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN) #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
# include "juce_gui_basics.h" # include "juce_gui_basics.h"
static juce::Array<void*> gActivePlugins;
using juce::ScopedJuceInitialiser_GUI;
using juce::SharedResourcePointer;
#endif #endif


// -----------------------------------------------------------------------
// -Weffc++ compat ext widget

extern "C" {

typedef struct _LV2_External_UI_Widget_Compat {
void (*run )(struct _LV2_External_UI_Widget_Compat*);
void (*show)(struct _LV2_External_UI_Widget_Compat*);
void (*hide)(struct _LV2_External_UI_Widget_Compat*);

_LV2_External_UI_Widget_Compat()
: run(nullptr), show(nullptr), hide(nullptr) {}

} LV2_External_UI_Widget_Compat;

}

// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// LV2 descriptor functions // LV2 descriptor functions


class NativePlugin : public LV2_External_UI_Widget
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Weffc++"
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Weffc++"
#endif
class NativePlugin : public LV2_External_UI_Widget_Compat
{ {
#if defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
# pragma GCC diagnostic pop
#endif
public: public:
static const uint32_t kMaxMidiEvents = 512; static const uint32_t kMaxMidiEvents = 512;


NativePlugin(const NativePluginDescriptor* const desc, const double sampleRate, const char* const bundlePath, const LV2_Feature* const* features) NativePlugin(const NativePluginDescriptor* const desc, const double sampleRate, const char* const bundlePath, const LV2_Feature* const* features)
: fHandle(nullptr), : fHandle(nullptr),
fHost(),
fDescriptor(desc), fDescriptor(desc),
fProgramDesc({0, 0, nullptr}),
fMidiEventCount(0), fMidiEventCount(0),
fTimeInfo(),
fIsProcessing(false), fIsProcessing(false),
fVolume(1.0f), fVolume(1.0f),
fDryWet(1.0f), fDryWet(1.0f),
fBufferSize(0), fBufferSize(0),
fSampleRate(sampleRate), fSampleRate(sampleRate),
fUridMap(nullptr)
fUridMap(nullptr),
fURIs(),
fUI(),
fPorts(),
#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
sJuceGUI(),
#endif
leakDetector_NativePlugin()
{ {
run = extui_run; run = extui_run;
show = extui_show; show = extui_show;
@@ -89,12 +129,6 @@ public:
fHost.ui_save_file = host_ui_save_file; fHost.ui_save_file = host_ui_save_file;
fHost.dispatcher = host_dispatcher; fHost.dispatcher = host_dispatcher;


#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
if (gActivePlugins.size() == 0)
juce::initialiseJuce_GUI();
gActivePlugins.add(this);
#endif

const LV2_Options_Option* options = nullptr; const LV2_Options_Option* options = nullptr;
const LV2_URID_Map* uridMap = nullptr; const LV2_URID_Map* uridMap = nullptr;
const LV2_URID_Unmap* uridUnmap = nullptr; const LV2_URID_Unmap* uridUnmap = nullptr;
@@ -160,14 +194,6 @@ public:
delete[] fHost.resourceDir; delete[] fHost.resourceDir;
fHost.resourceDir = nullptr; fHost.resourceDir = nullptr;
} }

#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
jassert(gActivePlugins.contains(this));
gActivePlugins.removeFirstMatchingValue(this);

if (gActivePlugins.size() == 0)
juce::shutdownJuce_GUI();
#endif
} }


bool init() bool init()
@@ -194,7 +220,7 @@ public:
carla_zeroStruct<NativeTimeInfo>(fTimeInfo); carla_zeroStruct<NativeTimeInfo>(fTimeInfo);


fPorts.init(fDescriptor, fHandle); fPorts.init(fDescriptor, fHandle);
fUris.map(fUridMap);
fURIs.map(fUridMap);


return true; return true;
} }
@@ -271,7 +297,7 @@ public:
if (event->time.frames >= frames) if (event->time.frames >= frames)
break; break;


if (event->body.type == fUris.midiEvent)
if (event->body.type == fURIs.midiEvent)
{ {
if (fMidiEventCount >= kMaxMidiEvents*2) if (fMidiEventCount >= kMaxMidiEvents*2)
continue; continue;
@@ -289,11 +315,11 @@ public:
continue; continue;
} }


if (event->body.type == fUris.atomBlank)
if (event->body.type == fURIs.atomBlank)
{ {
const LV2_Atom_Object* const obj((const LV2_Atom_Object*)&event->body); const LV2_Atom_Object* const obj((const LV2_Atom_Object*)&event->body);


if (obj->body.otype != fUris.timePos)
if (obj->body.otype != fURIs.timePos)
continue; continue;


LV2_Atom* bar = nullptr; LV2_Atom* bar = nullptr;
@@ -305,32 +331,32 @@ public:
LV2_Atom* speed = nullptr; LV2_Atom* speed = nullptr;


lv2_atom_object_get(obj, lv2_atom_object_get(obj,
fUris.timeBar, &bar,
fUris.timeBarBeat, &barBeat,
fUris.timeBeatsPerBar, &beatsPerBar,
fUris.timeBeatsPerMinute, &bpm,
fUris.timeBeatUnit, &beatUnit,
fUris.timeFrame, &frame,
fUris.timeSpeed, &speed,
fURIs.timeBar, &bar,
fURIs.timeBarBeat, &barBeat,
fURIs.timeBeatsPerBar, &beatsPerBar,
fURIs.timeBeatsPerMinute, &bpm,
fURIs.timeBeatUnit, &beatUnit,
fURIs.timeFrame, &frame,
fURIs.timeSpeed, &speed,
nullptr); nullptr);


if (bpm != nullptr && bpm->type == fUris.atomFloat)
if (bpm != nullptr && bpm->type == fURIs.atomFloat)
{ {
fTimeInfo.bbt.beatsPerMinute = ((LV2_Atom_Float*)bpm)->body; fTimeInfo.bbt.beatsPerMinute = ((LV2_Atom_Float*)bpm)->body;
fTimeInfo.bbt.valid = true; fTimeInfo.bbt.valid = true;
} }


if (beatsPerBar != nullptr && beatsPerBar->type == fUris.atomFloat)
if (beatsPerBar != nullptr && beatsPerBar->type == fURIs.atomFloat)
{ {
float beatsPerBarValue = ((LV2_Atom_Float*)beatsPerBar)->body; float beatsPerBarValue = ((LV2_Atom_Float*)beatsPerBar)->body;
fTimeInfo.bbt.beatsPerBar = beatsPerBarValue; fTimeInfo.bbt.beatsPerBar = beatsPerBarValue;


if (bar != nullptr && bar->type == fUris.atomLong)
if (bar != nullptr && bar->type == fURIs.atomLong)
{ {
//float barValue = ((LV2_Atom_Long*)bar)->body; //float barValue = ((LV2_Atom_Long*)bar)->body;
//curPosInfo.ppqPositionOfLastBarStart = barValue * beatsPerBarValue; //curPosInfo.ppqPositionOfLastBarStart = barValue * beatsPerBarValue;


if (barBeat != nullptr && barBeat->type == fUris.atomFloat)
if (barBeat != nullptr && barBeat->type == fURIs.atomFloat)
{ {
//float barBeatValue = ((LV2_Atom_Float*)barBeat)->body; //float barBeatValue = ((LV2_Atom_Float*)barBeat)->body;
//curPosInfo.ppqPosition = curPosInfo.ppqPositionOfLastBarStart + barBeatValue; //curPosInfo.ppqPosition = curPosInfo.ppqPositionOfLastBarStart + barBeatValue;
@@ -338,10 +364,10 @@ public:
} }
} }


if (beatUnit != nullptr && beatUnit->type == fUris.atomFloat)
if (beatUnit != nullptr && beatUnit->type == fURIs.atomFloat)
fTimeInfo.bbt.beatType = ((LV2_Atom_Float*)beatUnit)->body; fTimeInfo.bbt.beatType = ((LV2_Atom_Float*)beatUnit)->body;


if (frame != nullptr && frame->type == fUris.atomLong)
if (frame != nullptr && frame->type == fURIs.atomLong)
{ {
const int64_t value(((LV2_Atom_Long*)frame)->body); const int64_t value(((LV2_Atom_Long*)frame)->body);
CARLA_SAFE_ASSERT_CONTINUE(value >= 0); CARLA_SAFE_ASSERT_CONTINUE(value >= 0);
@@ -349,7 +375,7 @@ public:
fTimeInfo.frame = static_cast<uint64_t>(value); fTimeInfo.frame = static_cast<uint64_t>(value);
} }


if (speed != nullptr && speed->type == fUris.atomFloat)
if (speed != nullptr && speed->type == fURIs.atomFloat)
fTimeInfo.playing = ((LV2_Atom_Float*)speed)->body == 1.0f; fTimeInfo.playing = ((LV2_Atom_Float*)speed)->body == 1.0f;


continue; continue;
@@ -364,7 +390,7 @@ public:


if (event == nullptr) if (event == nullptr)
continue; continue;
if (event->body.type != fUris.midiEvent)
if (event->body.type != fURIs.midiEvent)
continue; continue;
if (event->body.size > 4) if (event->body.size > 4)
continue; continue;
@@ -498,7 +524,7 @@ public:


if (char* const state = fDescriptor->get_state(fHandle)) if (char* const state = fDescriptor->get_state(fHandle))
{ {
store(handle, fUridMap->map(fUridMap->handle, "http://kxstudio.sf.net/ns/carla/chunk"), state, std::strlen(state), fUris.atomString, LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE);
store(handle, fUridMap->map(fUridMap->handle, "http://kxstudio.sf.net/ns/carla/chunk"), state, std::strlen(state), fURIs.atomString, LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE);
std::free(state); std::free(state);
return LV2_STATE_SUCCESS; return LV2_STATE_SUCCESS;
} }
@@ -521,7 +547,7 @@ public:
return LV2_STATE_ERR_UNKNOWN; return LV2_STATE_ERR_UNKNOWN;
if (data == nullptr) if (data == nullptr)
return LV2_STATE_ERR_UNKNOWN; return LV2_STATE_ERR_UNKNOWN;
if (type != fUris.atomString)
if (type != fURIs.atomString)
return LV2_STATE_ERR_BAD_TYPE; return LV2_STATE_ERR_BAD_TYPE;


fDescriptor->set_state(fHandle, (const char*)data); fDescriptor->set_state(fHandle, (const char*)data);
@@ -889,7 +915,7 @@ private:
timeBeatsPerBar = uridMap->map(uridMap->handle, LV2_TIME__beatsPerBar); timeBeatsPerBar = uridMap->map(uridMap->handle, LV2_TIME__beatsPerBar);
timeBeatsPerMinute = uridMap->map(uridMap->handle, LV2_TIME__beatsPerMinute); timeBeatsPerMinute = uridMap->map(uridMap->handle, LV2_TIME__beatsPerMinute);
} }
} fUris;
} fURIs;


struct UI { struct UI {
const LV2_External_UI_Host* host; const LV2_External_UI_Host* host;
@@ -1092,21 +1118,25 @@ private:
CARLA_DECLARE_NON_COPY_STRUCT(Ports); CARLA_DECLARE_NON_COPY_STRUCT(Ports);
} fPorts; } fPorts;


#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
SharedResourcePointer<ScopedJuceInitialiser_GUI> sJuceGUI;
#endif

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


#define handlePtr ((NativePlugin*)_this_)
#define handlePtr ((NativePlugin*)self)


static void extui_run(LV2_External_UI_Widget* _this_)
static void extui_run(LV2_External_UI_Widget_Compat* self)
{ {
handlePtr->handleUiRun(); handlePtr->handleUiRun();
} }


static void extui_show(LV2_External_UI_Widget* _this_)
static void extui_show(LV2_External_UI_Widget_Compat* self)
{ {
handlePtr->handleUiShow(); handlePtr->handleUiShow();
} }


static void extui_hide(LV2_External_UI_Widget* _this_)
static void extui_hide(LV2_External_UI_Widget_Compat* self)
{ {
handlePtr->handleUiHide(); handlePtr->handleUiHide();
} }


+ 11
- 11
source/utils/LinkedList.hpp View File

@@ -24,7 +24,7 @@
// Define list_entry and list_entry_const // Define list_entry and list_entry_const


#ifndef offsetof #ifndef offsetof
# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
# define offsetof(TYPE, MEMBER) ((std::size_t) &((TYPE *)0)->MEMBER)
#endif #endif


#if (defined(__GNUC__) || defined(__clang__)) && ! defined(__STRICT_ANSI__) #if (defined(__GNUC__) || defined(__clang__)) && ! defined(__STRICT_ANSI__)
@@ -144,7 +144,7 @@ public:
_init(); _init();
} }


size_t count() const noexcept
std::size_t count() const noexcept
{ {
return fCount; return fCount;
} }
@@ -174,11 +174,11 @@ public:
return _add(value, false, it.fEntry->prev); return _add(value, false, it.fEntry->prev);
} }


const T& getAt(const size_t index, const T& fallback) const noexcept
const T& getAt(const std::size_t index, const T& fallback) const noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(fCount > 0 && index < fCount, fallback); CARLA_SAFE_ASSERT_RETURN(fCount > 0 && index < fCount, fallback);


size_t i = 0;
std::size_t i = 0;
ListHead* entry; ListHead* entry;
ListHead* entry2; ListHead* entry2;


@@ -193,11 +193,11 @@ public:
return fallback; return fallback;
} }


T& getAt(const size_t index, T& fallback) const noexcept
T& getAt(const std::size_t index, T& fallback) const noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(fCount > 0 && index < fCount, fallback); CARLA_SAFE_ASSERT_RETURN(fCount > 0 && index < fCount, fallback);


size_t i = 0;
std::size_t i = 0;
ListHead* entry; ListHead* entry;
ListHead* entry2; ListHead* entry2;


@@ -212,11 +212,11 @@ public:
return fallback; return fallback;
} }


T getAt(const size_t index, T& fallback, const bool removeObj) noexcept
T getAt(const std::size_t index, T& fallback, const bool removeObj) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(fCount > 0 && index < fCount, fallback); CARLA_SAFE_ASSERT_RETURN(fCount > 0 && index < fCount, fallback);


size_t i = 0;
std::size_t i = 0;
ListHead* entry; ListHead* entry;
ListHead* entry2; ListHead* entry2;


@@ -342,10 +342,10 @@ public:
} }


protected: protected:
const size_t kDataSize;
const std::size_t kDataSize;


size_t fCount;
ListHead fQueue;
std::size_t fCount;
ListHead fQueue;


virtual Data* _allocate() noexcept = 0; virtual Data* _allocate() noexcept = 0;
virtual void _deallocate(Data* const dataPtr) noexcept = 0; virtual void _deallocate(Data* const dataPtr) noexcept = 0;


Loading…
Cancel
Save