Browse Source

Alternative/better way to find all audio ports in juce plugins

tags/v2.3.0-RC1
falkTX 4 years ago
parent
commit
3cbfcf4fbb
2 changed files with 74 additions and 43 deletions
  1. +35
    -16
      source/backend/plugin/CarlaPluginJuce.cpp
  2. +39
    -27
      source/discovery/carla-discovery.cpp

+ 35
- 16
source/backend/plugin/CarlaPluginJuce.cpp View File

@@ -40,7 +40,6 @@
#define JUCE_GUI_BASICS_INCLUDE_XHEADERS 1
#include "AppConfig.h"
#include "juce_audio_processors/juce_audio_processors.h"
#include "juce_audio_processors/format_types/juce_VSTInterface.h"
#include "juce_gui_basics/juce_gui_basics.h"

#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
@@ -56,6 +55,38 @@ CARLA_BACKEND_START_NAMESPACE

static const ExternalMidiNote kExternalMidiNoteFallback = { -1, 0, 0 };

// -------------------------------------------------------------------------------------------------------------------
// find all available plugin audio ports

static void findMaxTotalChannels(juce::AudioProcessor* const filter, uint32_t& maxTotalIns, uint32_t& maxTotalOuts)
{
filter->enableAllBuses();

const int numInputBuses = filter->getBusCount(true);
const int numOutputBuses = filter->getBusCount(false);

if (numInputBuses > 1 || numOutputBuses > 1)
{
maxTotalIns = maxTotalOuts = 0;

for (int i = 0; i < numInputBuses; ++i)
maxTotalIns += static_cast<uint32_t>(juce::jmax(0, filter->getChannelCountOfBus(true, i)));

for (int i = 0; i < numOutputBuses; ++i)
maxTotalOuts += static_cast<uint32_t>(juce::jmax(0, filter->getChannelCountOfBus(false, i)));
}
else
{
maxTotalIns = numInputBuses > 0
? static_cast<uint32_t>(juce::jmax(0, filter->getBus(true, 0)->getMaxSupportedChannels(64)))
: 0;

maxTotalOuts = numOutputBuses > 0
? static_cast<uint32_t>(juce::jmax(0, filter->getBus(false, 0)->getMaxSupportedChannels(64)))
: 0;
}
}

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

class CarlaPluginJuce : public CarlaPlugin,
@@ -466,28 +497,16 @@ public:

clearBuffers();

fInstance->enableAllBuses();
fInstance->refreshParameterList();

uint32_t aIns, aOuts, mIns, mOuts, params;
mIns = mOuts = 0;

bool needsCtrlIn, needsCtrlOut;
needsCtrlIn = needsCtrlOut = false;

aIns = static_cast<uint32_t>(std::max(fInstance->getTotalNumInputChannels(), 0));
aOuts = static_cast<uint32_t>(std::max(fInstance->getTotalNumOutputChannels(), 0));
params = static_cast<uint32_t>(std::max(fInstance->getNumParameters(), 0));
findMaxTotalChannels(fInstance.get(), aIns, aOuts);
fInstance->refreshParameterList();

if (getType() == PLUGIN_VST2)
{
if (VstEffectInterface* const vst
= reinterpret_cast<VstEffectInterface*>(fInstance->getPlatformSpecificData()))
{
aIns = std::max(aIns, static_cast<uint32_t>(std::max(vst->numInputChannels, 0)));
aOuts = std::max(aOuts, static_cast<uint32_t>(std::max(vst->numOutputChannels, 0)));
}
}
params = static_cast<uint32_t>(std::max(fInstance->getNumParameters(), 0));

if (fInstance->acceptsMidi())
{


+ 39
- 27
source/discovery/carla-discovery.cpp View File

@@ -51,9 +51,7 @@
#include "CarlaLadspaUtils.hpp"
#include "CarlaLv2Utils.hpp"

#ifdef USING_JUCE_FOR_VST2
# include "juce_audio_processors/format_types/juce_VSTInterface.h"
#else
#ifndef USING_JUCE_FOR_VST2
# include "CarlaVstUtils.hpp"
#endif

@@ -96,7 +94,7 @@ using water::StringArray;

CARLA_BACKEND_USE_NAMESPACE

// --------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------
// Dummy values to test plugins with

static const uint32_t kBufferSize = 512;
@@ -104,7 +102,7 @@ static const double kSampleRate = 44100.0;
static const int32_t kSampleRatei = 44100;
static const float kSampleRatef = 44100.0f;

// --------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------
// Don't print ELF/EXE related errors since discovery can find multi-architecture binaries

static void print_lib_error(const char* const filename)
@@ -810,7 +808,7 @@ static void do_lv2_check(const char* const bundle, const bool doInit)
#endif

#ifndef USING_JUCE_FOR_VST2
// --------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------
// VST stuff

// Check if plugin is currently processing
@@ -1383,6 +1381,35 @@ static void do_vst_check(lib_t& libHandle, const char* const filename, const boo
#endif // ! USING_JUCE_FOR_VST2

#ifdef USING_JUCE
// -------------------------------------------------------------------------------------------------------------------
// find all available plugin audio ports

static void findMaxTotalChannels(juce::AudioProcessor* const filter, int& maxTotalIns, int& maxTotalOuts)
{
filter->enableAllBuses();

int numInputBuses = filter->getBusCount(true);
int numOutputBuses = filter->getBusCount(false);

if (numInputBuses > 1 || numOutputBuses > 1)
{
maxTotalIns = maxTotalOuts = 0;

for (int i = 0; i < numInputBuses; ++i)
maxTotalIns += filter->getChannelCountOfBus(true, i);

for (int i = 0; i < numOutputBuses; ++i)
maxTotalOuts += filter->getChannelCountOfBus(false, i);
}
else
{
maxTotalIns = numInputBuses > 0 ? filter->getBus(true, 0)->getMaxSupportedChannels(64) : 0;
maxTotalOuts = numOutputBuses > 0 ? filter->getBus(false, 0)->getMaxSupportedChannels(64) : 0;
}
}

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

static void do_juce_check(const char* const filename_, const char* const stype, const bool doInit)
{
CARLA_SAFE_ASSERT_RETURN(stype != nullptr && stype[0] != 0,) // FIXME
@@ -1475,24 +1502,9 @@ static void do_juce_check(const char* const filename_, const char* const stype,
{
carla_juce_idle();

instance->enableAllBuses();
findMaxTotalChannels(instance.get(), audioIns, audioOuts);
instance->refreshParameterList();

audioIns = instance->getTotalNumInputChannels();
audioOuts = instance->getTotalNumOutputChannels();

#if JUCE_PLUGINHOST_VST
if (std::strcmp(stype, "VST2") == 0)
{
if (VstEffectInterface* const vst
= reinterpret_cast<VstEffectInterface*>(instance->getPlatformSpecificData()))
{
audioIns = std::max(audioIns, std::max(vst->numInputChannels, 0));
audioOuts = std::max(audioOuts, std::max(vst->numOutputChannels, 0));
}
}
#endif

parameters = instance->getParameters().size();

if (instance->hasEditor())
@@ -1675,7 +1687,7 @@ int main(int argc, char* argv[])
openLib = false;
#endif

// ---------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------
// Initialize OS features

// we want stuff in English so we can parse error messages
@@ -1694,7 +1706,7 @@ int main(int argc, char* argv[])
# endif
#endif

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

if (openLib)
{
@@ -1713,7 +1725,7 @@ int main(int argc, char* argv[])
if (doInit && getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS") != nullptr)
doInit = false;

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

if (doInit && openLib && handle != nullptr)
{
@@ -1794,7 +1806,7 @@ int main(int argc, char* argv[])
if (openLib && handle != nullptr)
lib_close(handle);

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

#ifdef CARLA_OS_WIN
#ifndef __WINPTHREADS_VERSION
@@ -1808,4 +1820,4 @@ int main(int argc, char* argv[])
return 0;
}

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

Loading…
Cancel
Save