Skip to content

Commit

Permalink
Merge branch 'xnor/params'
Browse files Browse the repository at this point in the history
  • Loading branch information
x37v committed May 4, 2023
2 parents ea69d97 + c2b7eed commit 75fddac
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
44 changes: 39 additions & 5 deletions RNBO_JuceAudioProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,40 @@ JuceAudioProcessor::JuceAudioProcessor(
paramFactory = fact.get();
}

//get parameter desc
nlohmann::json paramdesc;
{
const std::string key = "parameters";
if (patcher_desc.contains(key) && patcher_desc[key].is_array()) {
paramdesc = patcher_desc[key];
}
}

int juceIndex = 0;
for (ParameterIndex i = 0; i < _rnboObject.getNumParameters(); i++) {
//create can return nullptr
juce::AudioProcessorParameter * p = paramFactory->create(_rnboObject, i);
if (p) {
_rnboParamIndexToJuceParamIndex.insert({i, juceIndex++});
addParameter(p);
#if RNBO_JUCE_PARAM_DEFAULT_NOTIFY
bool notify = true;
#else
bool notify = false;
#endif
//see if we have the notify meta
if (paramdesc.size() > i) {
const std::string meta = "meta";
const std::string key = "notify";
auto desc = paramdesc[i];
if (desc.contains(meta) && desc[meta].is_object() && desc[meta].contains(key) && desc[meta][key].is_boolean()) {
notify = desc[meta][key].get<bool>();
}
}

if (notify) {
_notifyingParameters.insert(i);
}
}
}

Expand Down Expand Up @@ -211,7 +238,7 @@ void JuceAudioProcessor::handleParameterEvent(const ParameterEvent& event)
if (_isInStartup || _isSettingPresetAsync) {
param->setValue((float)normalizedValue);
}
else {
else if (_notifyingParameters.count(event.getIndex()) != 0) {
param->beginChangeGesture();
param->setValueNotifyingHost((float)normalizedValue);
param->endChangeGesture();
Expand Down Expand Up @@ -635,12 +662,19 @@ juce::AudioProcessorParameter* JuceAudioParameterFactory::create(RNBO::CoreObjec
}
}

AudioProcessorParameter* JuceAudioParameterFactory::createEnum(RNBO::CoreObject& rnboObject, ParameterIndex index, const ParameterInfo& info, int versionHint, const nlohmann::json&) {
return new EnumParameter(index, info, rnboObject, versionHint);
AudioProcessorParameter* JuceAudioParameterFactory::createEnum(RNBO::CoreObject& rnboObject, ParameterIndex index, const ParameterInfo& info, int versionHint, const nlohmann::json& meta) {
return new EnumParameter(index, info, rnboObject, versionHint, automate(meta));
}

AudioProcessorParameter* JuceAudioParameterFactory::createFloat(RNBO::CoreObject& rnboObject, ParameterIndex index, const ParameterInfo& info, int versionHint, const nlohmann::json&) {
return new FloatParameter(index, info, rnboObject, versionHint);
AudioProcessorParameter* JuceAudioParameterFactory::createFloat(RNBO::CoreObject& rnboObject, ParameterIndex index, const ParameterInfo& info, int versionHint, const nlohmann::json& meta) {
return new FloatParameter(index, info, rnboObject, versionHint, automate(meta));
}

bool JuceAudioParameterFactory::automate(const nlohmann::json& meta) {
const std::string key = "automate";
if (meta.contains(key) && meta[key].is_boolean())
return meta[key].get<bool>();
return true;
}


Expand Down
17 changes: 14 additions & 3 deletions RNBO_JuceAudioProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace RNBO {
virtual juce::AudioProcessorParameter* createEnum(RNBO::CoreObject& rnboObject, ParameterIndex index, const ParameterInfo& info, int versionHint, const nlohmann::json& meta);
virtual juce::AudioProcessorParameter* createFloat(RNBO::CoreObject& rnboObject, ParameterIndex index, const ParameterInfo& info, int versionHint, const nlohmann::json& meta);

bool automate(const nlohmann::json& meta);

const nlohmann::json& _patcherDesc;
std::unordered_map<RNBO::ParameterIndex, nlohmann::json> _paramMeta;
};
Expand Down Expand Up @@ -170,13 +172,18 @@ namespace RNBO {
int _currentPresetIdx;
bool _isInStartup = false;
bool _isSettingPresetAsync = false;

//rnbo might have some invisible parameters that aren't given to juce, so we map the rnbo index to the juce index
std::unordered_map<RNBO::ParameterIndex, int> _rnboParamIndexToJuceParamIndex;

//which parameters should cause host notifications when coming out of the core object
std::set<RNBO::ParameterIndex> _notifyingParameters;

//id -> file name
std::unordered_map<juce::String, juce::String> _loadedDataRefs;
std::mutex _loadedDataRefsMutex;


double _lastBPM = -1.0;
int _lastTimeSigNumerator = 0;
int _lastTimeSigDenominator = 0;
Expand Down Expand Up @@ -206,14 +213,15 @@ namespace RNBO {
using String = juce::String;
public:

FloatParameter (ParameterIndex index, const ParameterInfo& info, CoreObject& rnboObject, int versionHint = 0)
FloatParameter (ParameterIndex index, const ParameterInfo& info, CoreObject& rnboObject, int versionHint = 0, bool automatable = true)
:
juce::RangedAudioParameter(
paramIdForRNBOParam(rnboObject, index, versionHint),
String(rnboObject.getParameterName(index))
)
, _index(index)
, _rnboObject(rnboObject)
, _automatable(automatable)
{

if (info.unit) {
Expand Down Expand Up @@ -293,22 +301,25 @@ namespace RNBO {
return _normRange;
}

bool isAutomatable() const override { return _automatable; }

protected:
ParameterIndex _index;
CoreObject& _rnboObject;
String _unitName;
String _name;
float _defaultValue;
juce::NormalisableRange<float> _normRange;
bool _automatable = true;
};

class EnumParameter : public FloatParameter
{
using String = juce::String;
public:

EnumParameter (ParameterIndex index, const ParameterInfo& info, CoreObject& rnboObject, int versionHint = 0)
: FloatParameter(index, info, rnboObject, versionHint)
EnumParameter (ParameterIndex index, const ParameterInfo& info, CoreObject& rnboObject, int versionHint = 0, bool automatable = true)
: FloatParameter(index, info, rnboObject, versionHint, automatable)
{
for (Index i = 0; i < static_cast<Index>(info.steps); i++) {
_enumValues.push_back(info.enumValues[i]);
Expand Down
8 changes: 7 additions & 1 deletion staticplugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ set(PLUGIN_MANUFACTURER_WEBSITE "http://www.cycling74.com" CACHE STRING "Specify
set(PLUGIN_MANUFACTURER_EMAIL "[email protected]" CACHE STRING "Specify the plugin author's email address")



set(PLUGIN_VST3_MAC OFF CACHE BOOL "Export VST3 Plugin for MacOS")
set(PLUGIN_VST3_WIN OFF CACHE BOOL "Export VST3 Plugin for Windows")
set(PLUGIN_VST3_LINUX OFF CACHE BOOL "Export VST3 Plugin for Linux")
Expand All @@ -44,6 +43,7 @@ set(PLUGIN_NEEDS_MIDI_INPUT OFF CACHE BOOL "Does the plugin need midi input?")
set(PLUGIN_NEEDS_MIDI_OUTPUT OFF CACHE BOOL "Does the plugin need midi output?")
set(PLUGIN_IS_MIDI_EFFECT OFF CACHE BOOL "Is this plugin a MIDI effect?")
#set(PLUGIN_EDITOR_WANTS_KEYBOARD_FOCUS OFF CACHE BOOL "Does the editor need keyboard focus?")
set(PLUGIN_PARAM_DEFAULT_NOTIFY OFF CACHE BOOL "Should parameter changes from inside your rnbo patch send output by default? Sometimes breaks automation.")

set(CONAN_PROFILE "default" CACHE STRING "The profile to use for building conan deps, this is useful for cross compiling")

Expand Down Expand Up @@ -161,6 +161,11 @@ if (PLUGIN_IS_MIDI_EFFECT)
set(JUCE_IS_MIDI_EFFECT 1)
endif()

set(RNBO_JUCE_PARAM_DEFAULT_NOTIFY 0)
if (PLUGIN_PARAM_DEFAULT_NOTIFY)
set(RNBO_JUCE_PARAM_DEFAULT_NOTIFY 1)
endif()


link_directories(${JUCEStaticPlugin_LIB_DIRS})

Expand Down Expand Up @@ -205,6 +210,7 @@ function(setup_common target_name target_type suffix bundle_extension)
JUCE_STATIC_PLUGIN=1
JUCE_DEBUG=${JUCE_DEBUG}
JucePlugin_IsMidiEffect=${JUCE_IS_MIDI_EFFECT}
RNBO_JUCE_PARAM_DEFAULT_NOTIFY=${RNBO_JUCE_PARAM_DEFAULT_NOTIFY}
)

if (PLUGIN_BUSES_PROPERTIES)
Expand Down

0 comments on commit 75fddac

Please sign in to comment.