Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to allow preset loading #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions Source/RenderEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
*/

#include "RenderEngine.h"
//==============================================================================
bool RenderEngine::loadPreset (const std::string& path)
{
MemoryBlock mb;
File file = File(path);
file.loadFileAsData(mb);
bool loaded = VSTPluginFormat::loadFromFXBFile (plugin, mb.getData(), mb.getSize());
return loaded;
}

//==============================================================================
bool RenderEngine::loadPlugin (const std::string& path)
Expand All @@ -34,7 +43,6 @@ bool RenderEngine::loadPlugin (const std::string& path)
String errorMessage;

if (plugin != nullptr) delete plugin;

plugin = pluginFormatManager.createPluginInstance (*pluginDescriptions[0],
sampleRate,
bufferSize,
Expand Down Expand Up @@ -66,12 +74,16 @@ bool RenderEngine::loadPlugin (const std::string& path)
void RenderEngine::renderPatch (const uint8 midiNote,
const uint8 midiVelocity,
const double noteLength,
const double renderLength)
const double renderLength,
const bool overridePatch)
{
// Get the overriden patch and set the vst parameters with it.
PluginPatch overridenPatch = getPatch();
for (const auto& parameter : overridenPatch)
plugin->setParameter (parameter.first, parameter.second);
// Get the overriden patch and set the vst parameters with it.
if (overridePatch)
{
PluginPatch overridenPatch = getPatch();
for (const auto& parameter : overridenPatch)
plugin->setParameter (parameter.first, parameter.second);
}

// Get the note on midiBuffer.
MidiMessage onMessage = MidiMessage::noteOn (1,
Expand Down Expand Up @@ -364,6 +376,18 @@ void RenderEngine::setPatch (const PluginPatch patch)
"\n- Current size: " << currentParameterSize <<
"\n- Supplied size: " << newPatchParameterSize << std::endl;
}
}

//==============================================================================
float RenderEngine::getParameter (const int parameter)
{
return plugin->getParameter (parameter);
}

//==============================================================================
void RenderEngine::setParameter (const int parameter, const float value)
{
plugin->setParameter (parameter, value);
}

//==============================================================================
Expand Down
14 changes: 10 additions & 4 deletions Source/RenderEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using namespace juce;

typedef std::vector<std::pair<int, float>> PluginPatch;
typedef std::vector<std::pair<int, float>> PluginPatch;
typedef std::vector<std::array<double, 13>> MFCCFeatures;

class RenderEngine
Expand All @@ -48,18 +48,24 @@ class RenderEngine
delete plugin;
}
}


bool loadPreset (const std::string& path);

bool loadPlugin (const std::string& path);

void setPatch (const PluginPatch patch);
void setPatch (const PluginPatch patch);

float getParameter (const int parameter);

void setParameter (const int parameter, const float value);

const PluginPatch getPatch();

void renderPatch (const uint8 midiNote,
const uint8 midiVelocity,
const double noteLength,
const double renderLength);
const double renderLength,
const bool overridePatch = true);

const MFCCFeatures getMFCCFrames();

Expand Down
21 changes: 18 additions & 3 deletions Source/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ namespace wrap
RenderEngine::setPatch(patch);
}

float wrapperGetParameter (int parameter)
{
return RenderEngine::getParameter(parameter);
}

void wrapperSetParameter (int parameter, float value)
{
RenderEngine::setParameter(parameter, value);
}

boost::python::list wrapperGetPatch()
{
return pluginPatchToListOfTuples (RenderEngine::getPatch());
Expand All @@ -126,7 +136,8 @@ namespace wrap
void wrapperRenderPatch (int midiNote,
int midiVelocity,
double noteLength,
double renderLength)
double renderLength,
bool overridePatch = true)
{
if (midiNote > 255) midiNote = 255;
if (midiNote < 0) midiNote = 0;
Expand All @@ -135,7 +146,8 @@ namespace wrap
RenderEngine::renderPatch(midiNote,
midiVelocity,
noteLength,
renderLength);
renderLength,
overridePatch);
}

boost::python::list wrapperGetMFCCFrames()
Expand Down Expand Up @@ -191,9 +203,12 @@ BOOST_PYTHON_MODULE(librenderman)
using namespace wrap;

class_<RenderEngineWrapper>("RenderEngine", init<int, int, int>())
.def("load_preset", &RenderEngineWrapper::loadPreset)
.def("load_plugin", &RenderEngineWrapper::loadPlugin)
.def("set_patch", &RenderEngineWrapper::wrapperSetPatch)
.def("get_patch", &RenderEngineWrapper::wrapperGetPatch)
.def("set_patch", &RenderEngineWrapper::wrapperSetPatch)
.def("get_parameter", &RenderEngineWrapper::wrapperGetParameter)
.def("set_parameter", &RenderEngineWrapper::wrapperSetParameter)
.def("render_patch", &RenderEngineWrapper::wrapperRenderPatch)
.def("get_mfcc_frames", &RenderEngineWrapper::wrapperGetMFCCFrames)
.def("get_plugin_parameter_size", &RenderEngineWrapper::wrapperGetPluginParameterSize)
Expand Down