@@ -478,8 +478,27 @@ class PluginVst : public ParameterAndNotesHelper
478
478
479
479
switch (opcode)
480
480
{
481
+ #if DISTRHO_PLUGIN_WANT_PROGRAMS
482
+ case VST_EFFECT_OPCODE_02: // set program
483
+ // Some hosts cannot distinguish between user presets (states) and built-in programs.
484
+ // They will invoke VST_EFFECT_OPCODE_02 (set program) regardless of the preset type.
485
+ // We need to set a switch when calling VST_EFFECT_OPCODE_18 (set chunk), and check it here,
486
+ // so that programs will not be loaded unexpectedly when loading a user preset.
487
+ if (fUserPresetLoaded )
488
+ {
489
+ fProgramIndex = 0 ;
490
+ fUserPresetLoaded = false ;
491
+ return 1 ;
492
+ }
493
+
494
+ fPlugin .loadProgram (value);
495
+ fProgramIndex = value;
496
+ return 1 ;
497
+ break ;
498
+ #endif
499
+
481
500
case VST_EFFECT_OPCODE_03: // get program
482
- return 0 ;
501
+ return fProgramIndex ;
483
502
484
503
case VST_EFFECT_OPCODE_04: // set program name
485
504
if (char * const programName = (char *)ptr)
@@ -500,7 +519,11 @@ class PluginVst : public ParameterAndNotesHelper
500
519
case VST_EFFECT_OPCODE_1D: // get program name indexed
501
520
if (char * const programName = (char *)ptr)
502
521
{
522
+ #if DISTRHO_PLUGIN_WANT_PROGRAMS
523
+ d_strncpy (programName, fPlugin .getProgramName (index), 24 );
524
+ #else
503
525
d_strncpy (programName, fProgramName , 24 );
526
+ #endif
504
527
return 1 ;
505
528
}
506
529
break ;
@@ -862,6 +885,9 @@ class PluginVst : public ParameterAndNotesHelper
862
885
}
863
886
}
864
887
888
+ // mark that we have loaded user preset from host
889
+ fUserPresetLoaded = true ;
890
+
865
891
return 1 ;
866
892
}
867
893
#endif // DISTRHO_PLUGIN_WANT_STATE
@@ -1123,6 +1149,8 @@ class PluginVst : public ParameterAndNotesHelper
1123
1149
1124
1150
// Temporary data
1125
1151
char fProgramName [32 ];
1152
+ int fProgramIndex = 0 ;
1153
+ int fUserPresetLoaded = false ;
1126
1154
1127
1155
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
1128
1156
uint32_t fMidiEventCount ;
@@ -1697,7 +1725,11 @@ const vst_effect* VSTPluginMain(const vst_host_callback audioMaster)
1697
1725
1698
1726
// plugin fields
1699
1727
effect->num_params = numParams;
1728
+ #if DISTRHO_PLUGIN_WANT_PROGRAMS
1729
+ effect->num_programs = sPlugin ->getProgramCount ();
1730
+ #else
1700
1731
effect->num_programs = 1 ;
1732
+ #endif
1701
1733
effect->num_inputs = DISTRHO_PLUGIN_NUM_INPUTS;
1702
1734
effect->num_outputs = DISTRHO_PLUGIN_NUM_OUTPUTS;
1703
1735
0 commit comments