Skip to content

Commit

Permalink
BREAKING
Browse files Browse the repository at this point in the history
dplug:host API has changed to be nothrow @nogc and avoid exceptions. This is the last part of the Dplug API which used a D runtime.
This that wasn't a high quality API in the first place, unless you use dplug:host you probably have nothing to fear.
- createPluginHost can now return null, must be paired with destroyPluginHost who also closes the dynlib
- host.close(); is deprecated
- saveChunk / restoreChunk now report failure
- string getters such host.getParameterName now return a const(char)[] string, zero-terminated, owned by dplug:host
- no more global reverse map in VST hosting
  • Loading branch information
Guillaume Piolat committed Oct 27, 2023
1 parent bb748d0 commit b29b788
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 91 deletions.
35 changes: 24 additions & 11 deletions host/dplug/host/host.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
*/
module dplug.host.host;

nothrow @nogc:

interface IPluginHost
{
nothrow @nogc:

/// Process some audio.
/// `setSampleRate` and `setMaxBufferSize` must be called before use.
/// samples must <= the maximum buffer size asked in
Expand All @@ -28,6 +32,7 @@ interface IPluginHost
float getParameter(int paramIndex);

/// Returns: Full name for parameter.
/// Lifetime of return value is same as IPluginHost.
const(char)[] getParameterName(int paramIndex);

/// Returns: Number of parameters.
Expand All @@ -36,26 +41,32 @@ interface IPluginHost
/// Loads a preset.
void loadPreset(int presetIndex);

/// Serialize state of the plugin.
ubyte[] saveState();
/// Serialize state of the plugin, to restore with `restoreState`.
///
/// Returns: `null` in case of error, else a state chunk.
/// The lifetime of this returned chunk is the same as the `IPluginHost`, or until
/// another call to `saveState` is done.
const(ubyte)[] saveState();

/// Restore state of the plugin.
void restoreState(ubyte[] chunk);
/// Restore state of the plugin, saved with `saveState`.
/// Returns: `true` on success.
bool restoreState(const(ubyte)[] chunk);

/// Gets current "program" index.
/// Note: not all presets are exposed to the host. In many plug-ins they aren't.
int getCurrentProgram();

/// Free all resources associated with the plugin host.
void close();

/// Get plugin information
string getProductString();
/// Get plugin information.
/// Lifetime of return value is same as IPluginHost.
const(char)[] getProductString();

///ditto
string getEffectName();
/// Lifetime of return value is same as IPluginHost.
const(char)[] getEffectName();

///ditto
string getVendorString();
/// Lifetime of return value is same as IPluginHost.
const(char)[] getVendorString();

/// Opens the editor window.
/// On Windows, pass a HWND
Expand All @@ -82,6 +93,8 @@ interface IPluginHost

/// Get tail size in seconds. Precise semantics TBD.
double getTailSizeInSeconds();

deprecated("Use destroyPluginHost() instead") void close();
}


16 changes: 13 additions & 3 deletions host/dplug/host/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ public import dplug.host.host;
public import dplug.host.vst2;
public import dplug.host.window;

nothrow @nogc:

/// Loads an audio plugin.
/// Such a host MUST be destroyed with `destroyPluginHost`.
/// Return: a plugin host, or `null` on error.
IPluginHost createPluginHost(string dynlibPath)
{
// FUTURE support OSX plugin bundles
Expand All @@ -26,13 +29,20 @@ IPluginHost createPluginHost(string dynlibPath)
{
version(VST2)
{
return new VST2PluginHost(lib.disown);
bool err;
VST2PluginHost instance = mallocNew!VST2PluginHost(lib.disown, &err);
if (err)
{
destroyFree(instance);
return null; // TODO: shall call destructor?
}
return instance;
}
else
throw new Exception("Couldn't load plugin: VST 2.4 format not supported");
return null; // VST 2.4 not supported
}
else
throw new Exception("Couldn't load plugin: unknown format");
return null; // unknown format
}

/// Destroy a plugin host created with `createPluginHost`.
Expand Down
Loading

0 comments on commit b29b788

Please sign in to comment.