Skip to content

Commit 5dde825

Browse files
Merge branch 'fixes' of https://github.com/cucuwritescode/faust2clap into fixes
2 parents cb84569 + c26e81a commit 5dde825

6 files changed

Lines changed: 95 additions & 48 deletions

File tree

architecture/max-msp/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# faust2max6/faust2msp
22

3-
The **faust2max6/faust2msp** tools transform a Faust DSP program into a compiled Max/MSP external, and a ready-to-use patch to load and use it. Polyphonic and MIDI controllable instruments can be created. Note that **faust2msp** is the old version compiling 32 bits external for Max5, and **faust2max6** compiles 64 bits for Max6 and newer versions, and should be preferably used.
3+
The **faust2max6/faust2msp** tools transform a Faust DSP program into a compiled Max/MSP external, and a ready-to-use patch to load and use it, containing the control GUI. Polyphonic and MIDI controllable instruments can be created. Note that **faust2msp** is the old version compiling 32 bits external for Max5, and **faust2max6** compiles 64 bits for Max6 and newer versions, and should be preferably used.
44

55
## How to use
66

@@ -90,6 +90,21 @@ If you plan to use **faust2max6/faust2msp** on your own machine, you will have t
9090

9191
- the original DSP file as well as the compiled self-contained C++ file are kept in the compiled `.mxo` external, to be accessed using the *Show Package Contents* option.
9292

93+
# faust2gen
94+
95+
The **faust2gen** tool transforms a Faust DSP program into a ready-to-use patch containing a **faustgen~/mc.faustgen~** object to compile it. Polyphonic and MIDI controllable patches can be created. The `read` message with the given DSP filename is added in the patch, so that the DSP code can be read and compiled. The control GUI is automatically created and connected to the **faustgen~/mc.faustgen~** object after the compilation step. The DSP code can be edited with an external editor. After the DSP code has been changed externally, the `read` message has to be used again to trigger compilation and GUI update.
96+
97+
## How to use
98+
99+
**faust2gen** is used with the following options: `faust2gen [-nvoices <num>] [-mc] <file.dsp>`
100+
101+
## Options
102+
103+
Here are the available options:
104+
105+
- `-nvoices <num>` : to produce a polyphonic ready patch to be used with MIDI events
106+
- `-mc` : to use a mc.faustgen~ object
107+
93108
# faust2rnbo
94109

95110
The **faust2rnbo** tool transforms a Faust DSP program into a RNBO patch including the generated codebox code. Polyphonic and MIDI controllable instruments can be created. The `-sp` option allows to generate as a reusable rnbopat file. Two rnbopat files will always be generated in polyphonic mode with an effect, since using abstractions is the appropriate model to combine the DSP and effect in a single `rnbo~`object. Additional options are used to generate a special version of the RNBO patch used in the testing infrastructure.

architecture/max-msp/ui.js

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
// ui.js
33
// -----------------
44
//
5-
// Automatically (re)generate/destroy sliders according to Faust DSP module
5+
// Automatically (re)generate/destroy sliders/buttons according to Faust DSP module.
66
// By Edgar Berdahl, July 2014
7-
// Grame, 2014-2016
7+
// Revised by Grame, 2014-2025
88
//
99
// Currently addHorizontalBargraph, addVerticalBargraph, declare,
10-
// openTabBox, openHorizontalBox, openVerticalBox, and closeBox are not really handled.
10+
// openTabBox, openHorizontalBox, openVerticalBox, and closeBox are not handled.
1111
//
1212
// Started from autosurface.js by rld, 5.04
1313
//
1414

1515
// Global table
16-
const dsp_ui_table = [];
16+
var dsp_ui_table = (typeof dsp_ui_table === 'undefined') ? [] : dsp_ui_table;
1717

18-
const faust = faust || {};
18+
var faust = (typeof faust === 'undefined') ? {} : faust;
1919

2020
// global variables and arrays
2121
faust.numwidgets = -1;
@@ -26,47 +26,85 @@ faust.theSliders = new Array(128);
2626
faust.theMessages = new Array(128);
2727
faust.thenumberBoxes = new Array(128);
2828

29-
faust.ui = function (json, patcher) {
29+
// Function to check if a string starts with a prefix
30+
faust.starts_with = function (str, prefix) {
31+
return (str.lastIndexOf(prefix, 0) === 0);
32+
}
3033

31-
var widgHeight = 30;
32-
var hBase = 150;
34+
// Function to get the DSP object by its name of class
35+
faust.get_with_name = function (patcher, name) {
36+
var obj = patcher.firstobject;
37+
while (obj) {
38+
if (faust.starts_with(obj.varname, name) || faust.starts_with(obj.maxclass, name)) {
39+
return obj;
40+
}
41+
obj = obj.nextobject;
42+
}
43+
return null;
44+
}
3345

34-
starts_with = function (str, prefix) {
35-
return (str.lastIndexOf(prefix, 0) === 0);
46+
// Function to remove all existing faust UI objects
47+
faust.remove_ui = function () {
48+
// Remove comments
49+
for (var i = 0; i < faust.theComments.length; i++) {
50+
patcher.remove(faust.theComments[i]);
3651
}
52+
faust.theComments = [];
3753

38-
getDSPName = function (patcher, name) {
39-
var obj = patcher.firstobject;
40-
while (obj) {
41-
if (starts_with(obj.varname, name)) {
42-
return obj;
43-
}
44-
obj = obj.nextobject;
45-
}
46-
return null;
54+
// Remove sliders
55+
for (var i = 0; i < faust.theSliders.length; i++) {
56+
patcher.remove(faust.theSliders[i]);
57+
}
58+
faust.theSliders = [];
59+
60+
// Remove messages
61+
for (var i = 0; i < faust.theMessages.length; i++) {
62+
patcher.remove(faust.theMessages[i]);
4763
}
64+
faust.theMessages = [];
65+
66+
// Remove number boxes
67+
for (var i = 0; i < faust.thenumberBoxes.length; i++) {
68+
patcher.remove(faust.thenumberBoxes[i]);
69+
}
70+
faust.thenumberBoxes = [];
71+
72+
// Reset the counter
73+
faust.numwidgets = 0;
74+
};
75+
76+
// Main function
77+
faust.ui = function (json, patcher) {
78+
79+
var widgHeight = 30;
80+
var hBase = 150;
4881

4982
// JSON parsing
83+
84+
// Recursive functions to parse the JSON UI description
5085
parse_ui = function (ui, target, patcher) {
5186
var i;
5287
for (i = 0; i < ui.length; i++) {
5388
parse_group(ui[i], target, patcher);
5489
}
5590
}
5691

92+
// Parse a group
5793
parse_group = function (group, target, patcher) {
5894
if (group.items) {
5995
parse_items(group.items, target, patcher);
6096
}
6197
}
6298

99+
// Parse items in a group
63100
parse_items = function (items, target, patcher) {
64101
var i;
65102
for (i = 0; i < items.length; i++) {
66103
parse_item(items[i], target, patcher);
67104
}
68105
}
69106

107+
// Parse a single item
70108
parse_item = function (item, target, patcher) {
71109
if (item.type === "vgroup" || item.type === "hgroup" || item.type === "tgroup") {
72110

@@ -190,29 +228,23 @@ faust.ui = function (json, patcher) {
190228
}
191229

192230
// Remove old
193-
while (faust.numwidgets >= 0) {
194-
patcher.remove(faust.theComments[faust.numwidgets]);
195-
patcher.remove(faust.theSliders[faust.numwidgets]);
196-
patcher.remove(faust.theMessages[faust.numwidgets]);
197-
patcher.remove(faust.thenumberBoxes[faust.numwidgets]);
198-
faust.numwidgets--;
199-
}
231+
faust.remove_ui();
200232

201233
// Create new
202-
var parsed_json = JSON.parse(json);
234+
const parsed_json = JSON.parse(json);
203235

204236
// Tries to find the compiled object from the "name" field in the JSON
205-
var dsp_object1 = patcher.getnamed(parsed_json.name + "~");
206-
if (dsp_object1 !== patcher.getnamed("null_object")) {
207-
parse_ui(parsed_json.ui, dsp_object1, patcher);
237+
var dsp_object = patcher.getnamed(parsed_json.name + "~");
238+
if (dsp_object !== patcher.getnamed("null_object")) {
239+
parse_ui(parsed_json.ui, dsp_object, patcher);
208240
} else {
209241
// Tries to find the compiled object from the "filename" field in the JSON
210-
var dsp_object2 = patcher.getnamed(parsed_json.filename.slice(0, -4) + "~");
211-
if (dsp_object2 !== patcher.getnamed("null_object")) {
212-
parse_ui(parsed_json.ui, dsp_object2, patcher);
242+
dsp_object = patcher.getnamed(parsed_json.filename.slice(0, -4) + "~");
243+
if (dsp_object !== patcher.getnamed("null_object")) {
244+
parse_ui(parsed_json.ui, dsp_object, patcher);
213245
} else {
214246
// Tries to find the compiled object from the "name" argument (used with faustgen~)
215-
var dsp_object = getDSPName(patcher, "faustgen");
247+
dsp_object = faust.get_with_name(patcher, "faustgen");
216248
if (dsp_object !== patcher.getnamed("null_object")) {
217249
parse_ui(parsed_json.ui, dsp_object, patcher);
218250
} else {
@@ -222,8 +254,9 @@ faust.ui = function (json, patcher) {
222254
}
223255
}
224256

257+
// Main entry point
225258
function anything() {
226-
var args = arrayfromargs(messagename, arguments);
259+
const args = arrayfromargs(messagename, arguments);
227260
dsp_ui_table.push(faust.ui(args[1], this.patcher));
228261
}
229262

compiler/generator/llvm/llvm_code_container.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ dsp_factory_base* LLVMCodeContainer::produceFactory()
283283

284284
// Possibly link with additional LLVM modules
285285
if (!linkAllModules(fContext, fModule, error)) {
286-
throw faustexception("ERROR : " + error);
286+
throw faustexception("ERROR/LLVM : " + error);
287287
}
288288

289289
return new llvm_dynamic_dsp_factory_aux("", fModule, fContext, "", -1);

compiler/generator/llvm/llvm_dsp_aux.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ uint64_t llvm_dsp_factory_aux::loadOptimize(const string& function, bool strict)
103103
return fun;
104104
} else if (strict) {
105105
stringstream error;
106-
error << "ERROR : loadOptimize failed for '" << function << "'\n";
106+
error << "ERROR/LLVM : loadOptimize failed for '" << function << "'\n";
107107
throw faustexception(error.str());
108108
} else {
109109
return 0;
@@ -195,7 +195,7 @@ llvm_dsp_factory_aux::~llvm_dsp_factory_aux()
195195

196196
void llvm_dsp_factory_aux::LLVMFatalErrorHandler(const char* reason)
197197
{
198-
throw faustexception("ERROR : " + string(reason));
198+
throw faustexception("ERROR/LLVM : " + string(reason));
199199
}
200200

201201
void llvm_dsp_factory_aux::init(const string& type_name, const string& dsp_name)

embedded/faustgen/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ Depending of the number of audio inputs and outputs described in the DSP source
4747

4848
When double-clicking on it, the **faustgen~/mc.faustgen~** object opens several menu items:
4949

50-
- *Edit DSP code* allows to open the integrated text editor, edit the DSP code, then JIT compile it when the window is closed
51-
- *View DSP parameters* print each parameters in the Max console window with its label, complete path (as *xxx/yyy/zzz* syntax) and range, as well as the complete DSP JSON
52-
- *View compile options* print all Faust compilation options in the Max console window
53-
- *View SVG digram* creates the block diagram SVG view and opens it in a browser
54-
- *View Web documention* access the standard Faust documention in a browser
55-
- *View libraries* open the embedded Faust libraies in a text editor
50+
- *Edit DSP code*: allows to open the integrated text editor, edit the DSP code, then JIT compile it when the window is closed
51+
- *View DSP parameters*: print each parameters in the Max console window with its label, complete path (as *xxx/yyy/zzz* syntax) and range, as well as the complete DSP JSON
52+
- *View compile options*: print all Faust compilation options in the Max console window
53+
- *View SVG diagram*: creates the block diagram SVG view and opens it in a browser
54+
- *View Web documention*: access the standard Faust documention in a browser
55+
- *View libraries*: open the embedded Faust libraies in a text editor
5656

5757
### Controlling
5858

tools/faust2appls/faust2gen

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ JSFILE_PATH="ui.js"
2020
echoHelp()
2121
{
2222
usage faust2gen "[options] <file.dsp>"
23-
require Max/MSP SDK
2423
echo "Compiles Faust programs to a fausgen~/mc.faustgen patch"
2524
option
26-
option '-nvoices <num>'
27-
option -mc "to activate multi-channels model"
25+
echo ' -nvoices <num> : to produce a polyphonic ready patch to be used with MIDI events'
26+
echo ' -mc : to use a mc.faustgen~ object'
2827
exit
2928
}
3029

0 commit comments

Comments
 (0)