Skip to content

Commit

Permalink
dplug-build can launche the Faust invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Piolat committed Dec 4, 2024
1 parent 2501a70 commit e5ddd2e
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 16 deletions.
3 changes: 1 addition & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
This one explains how to build an UI using `dplug:flat-widgets`.
* `examples/distort`: A distortion plugin, with a PBR UI.
This one explains how to use `TimedFIFO` for UI feedback, `Canvas`, `ImageKnob`, Wren scripting, custom widgets that draw to both Raw and PBR layer.


* `examples/faust-example`: A FreeVerb example using Faust.


### Other Examples
Expand Down
4 changes: 0 additions & 4 deletions examples/faust-example/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@

"targetType": "dynamicLibrary",

"preBuildCommands": [
"faust dsp/freeverb.dsp -lang dlang -a dplug.d -cn Freeverb -vec -o source/freeverb.d"
],

"configurations": [
{
"name": "CLAP",
Expand Down
8 changes: 7 additions & 1 deletion examples/faust-example/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@
"hasGUI": true,
"category": "effectReverb",

"licensePath": "LICENSE.md"
"licensePath": "LICENSE.md",

"comment-faust": "Use these keys to control the faust compiler invoked by dplug-build",
"faustSourceFiles": ["dsp/freeverb.dsp"],
"faustFlags": ["-double"],
"faustOutput": "source/freeverb.d",
"faustClassName": "Freeverb"
}
39 changes: 39 additions & 0 deletions tools/dplug-build/source/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,45 @@ int main(string[] args)
}
}

// (optional) Faust compilation step.
if (plugin.hasFaust)
{
if (!quiet) cwritefln("*** Faust compilation... ");

string faustBinary = "faust";
if (!plugin.faustOutput)
throw new Exception("Should have a \"faustOutput\" variable in plugin.json");

string className = plugin.faustClassName;
string sources = "";
foreach(sourceRel; plugin.faustSourceFiles)
{
string sourceAbs = buildPath(rootDir, sourceRel).array.to!string;
sources ~= " " ~ escapeShellArgument(sourceAbs);
}
string flags = " ";
foreach(f; plugin.faustFlags)
{
flags ~= f ~ " ";
}
string outputAbs;
if (plugin.faustOutput)
{
outputAbs = buildPath(rootDir, plugin.faustOutput).array.to!string;
}
else
throw new Exception("Should have a \"faustOutput\" variable in plugin.json");

string cmd = format("%s%s -lang dlang -a dplug.d -cn %s -vec%s -o %s",
faustBinary,
sources,
plugin.faustClassName,
flags,
outputAbs);
safeCommand(cmd);
if (!quiet) cwritefln(" => OK\n".lgreen);
}

// Build various configuration
foreach(config; configurations)
buildAndPackage(config, archs, iconPathOSX);
Expand Down
67 changes: 58 additions & 9 deletions tools/dplug-build/source/plugin.d
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ struct Plugin

PluginCategory category;


// <faust things>
// See faust-example for usage in plugin.json
string[] faustSourceFiles;
string[] faustFlags;
string faustOutput;
string faustClassName;
bool hasFaust() { return faustSourceFiles.length != 0; }
// </faust things>

string prettyName() pure const nothrow
{
return vendorName ~ " " ~ pluginName;
Expand Down Expand Up @@ -1068,15 +1078,6 @@ Plugin readPluginDescription(string rootDir, bool quiet, bool verbose)
throw new Exception("\"publicVersion\" should follow the form x.y.z with 3 integers (eg: \"1.0.0\")");
}

bool toBoolean(JSONValue value)
{
if (value.type == jsonTrue)
return true;
if (value.type == jsonFalse)
return false;
throw new Exception("Expected a boolean");
}

try
{
result.isSynth = toBoolean(rawPluginFile["isSynth"]);
Expand Down Expand Up @@ -1184,6 +1185,17 @@ Plugin readPluginDescription(string rootDir, bool quiet, bool verbose)
result.wrapConfigGUID = null;
}

// <faust>
if ("faustSourceFiles" in rawPluginFile)
result.faustSourceFiles = jsonStringArray("faustSourceFiles", rawPluginFile["faustSourceFiles"]);
if ("faustFlags" in rawPluginFile)
result.faustFlags ~= jsonStringArray("faustFlags", rawPluginFile["faustFlags"]);
if ("faustOutput" in rawPluginFile)
result.faustOutput = jsonString("faustOutput", rawPluginFile["faustOutput"]);
if ("faustClassName" in rawPluginFile)
result.faustClassName = jsonString("faustClassName", rawPluginFile["faustClassName"]);
// </faust>

return result;
}

Expand Down Expand Up @@ -1486,3 +1498,40 @@ string makeRSRC_with_Rez(Plugin plugin, Arch arch, bool verbose)
cwriteln();
return rsrcPath;
}

bool toBoolean(JSONValue value)
{
if (value.type == jsonTrue)
return true;
if (value.type == jsonFalse)
return false;
throw new Exception("Expected a boolean");
}

string jsonString(const(char)[] keyName, JSONValue value)
{
if (value.type == JSONType.string)
{
return value.str;
}
else
throw new Exception(format("Key %s should be a string", keyName));
}

string[] jsonStringArray(const(char)[] arrayName, JSONValue value)
{
if (value.type == JSONType.array)
{
string[] res;
JSONValue[] arr = value.array;

for (size_t n = 0; n < arr.length; ++n)
{
string keyName = format("%s[%s]", arrayName, n);
res ~= jsonString(keyName, arr[n]);
}
return res;
}
else
throw new Exception("Key %s should be a string array");
}

0 comments on commit e5ddd2e

Please sign in to comment.