Skip to content

VST2: Implement programs #401

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions distrho/src/DistrhoPluginVST2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ class PluginVst : public ParameterAndNotesHelper
std::memset(fProgramName, 0, sizeof(fProgramName));
std::strcpy(fProgramName, "Default");

#if DISTRHO_PLUGIN_WANT_PROGRAMS
fProgramIndex = 0;
fUserPresetLoaded = false;
#endif

const uint32_t parameterCount = fPlugin.getParameterCount();

if (parameterCount != 0)
Expand Down Expand Up @@ -478,8 +483,31 @@ class PluginVst : public ParameterAndNotesHelper

switch (opcode)
{
#if DISTRHO_PLUGIN_WANT_PROGRAMS
case VST_EFFECT_OPCODE_02: // set program
// Some hosts cannot distinguish between user presets (states) and built-in programs.
// They will invoke VST_EFFECT_OPCODE_02 (set program) regardless of the preset type.
// We need to set a switch when calling VST_EFFECT_OPCODE_18 (set chunk), and check it here,
// so that programs will not be loaded unexpectedly when loading a user preset.
if (fUserPresetLoaded)
{
fProgramIndex = 0;
fUserPresetLoaded = false;
return 1;
}

fPlugin.loadProgram(value);
fProgramIndex = value;
return 1;
break;
#endif

case VST_EFFECT_OPCODE_03: // get program
#if DISTRHO_PLUGIN_WANT_PROGRAMS
return fProgramIndex;
#else
return 0;
#endif

case VST_EFFECT_OPCODE_04: // set program name
if (char* const programName = (char*)ptr)
Expand All @@ -500,7 +528,11 @@ class PluginVst : public ParameterAndNotesHelper
case VST_EFFECT_OPCODE_1D: // get program name indexed
if (char* const programName = (char*)ptr)
{
#if DISTRHO_PLUGIN_WANT_PROGRAMS
d_strncpy(programName, fPlugin.getProgramName(index), 24);
#else
d_strncpy(programName, fProgramName, 24);
#endif
return 1;
}
break;
Expand Down Expand Up @@ -862,6 +894,11 @@ class PluginVst : public ParameterAndNotesHelper
}
}

# if DISTRHO_PLUGIN_WANT_PROGRAMS
// mark that we have loaded user preset from host
fUserPresetLoaded = true;
# endif

return 1;
}
#endif // DISTRHO_PLUGIN_WANT_STATE
Expand Down Expand Up @@ -1124,6 +1161,11 @@ class PluginVst : public ParameterAndNotesHelper
// Temporary data
char fProgramName[32];

#if DISTRHO_PLUGIN_WANT_PROGRAMS
int fProgramIndex;
bool fUserPresetLoaded;
#endif

#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
uint32_t fMidiEventCount;
MidiEvent fMidiEvents[kMaxMidiEvents];
Expand Down Expand Up @@ -1697,7 +1739,11 @@ const vst_effect* VSTPluginMain(const vst_host_callback audioMaster)

// plugin fields
effect->num_params = numParams;
#if DISTRHO_PLUGIN_WANT_PROGRAMS
effect->num_programs = sPlugin->getProgramCount();
#else
effect->num_programs = 1;
#endif
effect->num_inputs = DISTRHO_PLUGIN_NUM_INPUTS;
effect->num_outputs = DISTRHO_PLUGIN_NUM_OUTPUTS;

Expand Down