summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2024-04-30 10:03:38 +0200
committerRicardo Wurmus <rekado@elephly.net>2024-04-30 10:03:38 +0200
commit876c2d271a84693da15ef0678b456b758c8ad8fe (patch)
tree4e9750ca8318dee4531fa47cd523f9ec0eb9789b
parent0eee953a79e8ee8deb86b9ec2ff18dbbf3afb11e (diff)
Fill metadata from the Faust source file.
-rw-r--r--faust-ksoloti-object.c8
-rwxr-xr-xfaust2axo.py55
2 files changed, 43 insertions, 20 deletions
diff --git a/faust-ksoloti-object.c b/faust-ksoloti-object.c
index 97128fe..8524906 100644
--- a/faust-ksoloti-object.c
+++ b/faust-ksoloti-object.c
@@ -1,8 +1,8 @@
<objdefs>
- <obj.normal id="moog_vcf_2b" uuid="0009f089dced01ba64f7e22ac77fd78fbec47db9" sha="000d84e43d5934e94f32e1d50318f8feede69769">
- <sDescription>Moog VCF (moog_vcf_2b)</sDescription>
- <author>Ricardo Wurmus (Ksoloti), Julius O. Smith III (Faust)</author>
- <license>STK-4.3</license>
+ <obj.normal id="<<NAME>>" uuid="<<UUID>>" sha="000d84e43d5934e94f32e1d50318f8feede69769">
+ <sDescription><<DESCRIPTION>></sDescription>
+ <author><<AUTHOR>></author>
+ <license><<LICENSE>></license>
<helpPatch/>
<includes>
<include>math.h</include>
diff --git a/faust2axo.py b/faust2axo.py
index 7a65001..c37a507 100755
--- a/faust2axo.py
+++ b/faust2axo.py
@@ -3,6 +3,7 @@
import sys
import argparse
import subprocess
+import uuid
import xml.etree.ElementTree as ET
@@ -45,18 +46,28 @@ def process_sliders(xml):
else:
param_type = "frac32.s.map"
- inlets += f"<frac32 name=\"{label}\" />\n"
- params += f"<{param_type} name=\"{label}\" />\n"
+ inlets += f'<frac32 name="{label}" />\n'
+ params += f'<{param_type} name="{label}" />\n'
# TODO: summation and conversion based on type
if pitch:
- output += f"uint32_t {label} = mtof48k_ext_q31(param_{label} + inlet_{label});\n"
+ output += (
+ f"uint32_t {label} = mtof48k_ext_q31(param_{label} + inlet_{label});\n"
+ )
else:
output += f"uint32_t {label} = param_{label} + inlet_{label};\n"
output += f"mdsp.{varname} = fminf(1.0f, q27_to_float({label})) * {max};\n"
return (inlets, params, output)
+def safe_extract_text(xml, xpath, alternative):
+ result = xml.find(xpath)
+ if isinstance(result, ET.Element):
+ return result.text
+ else:
+ return alternative
+
+
def massage_output(oldfile, newfile, xml):
"""
Process the Faust output.
@@ -65,15 +76,35 @@ def massage_output(oldfile, newfile, xml):
# - throw everything before <objdefs> away
# - throw everything after </objdefs> away
# - remove extern "C" chunk (wrapped in "#ifdef __cplusplus")
+ # - inject params and inlets
# - replace scaling factors for sliders
# - replace metadata
+ id = uuid.uuid4()
+ author = safe_extract_text(xml, "./author", "unknown")
+ name = safe_extract_text(xml, "./name", "unnamed")
+ license = safe_extract_text(xml, "./license", "CC-SA 4.0")
+ description = safe_extract_text(
+ xml, "./description", "Generated from Faust DSP code."
+ )
+
inlets, params, conversions = process_sliders(xml)
-
+
seen_start = False
seen_end = False
skip_ifdef = False
+ replacements = {
+ "UUID": str(id),
+ "AUTHOR": author,
+ "NAME": name,
+ "LICENSE": license,
+ "DESCRIPTION": description,
+ "INLETS": inlets,
+ "PARAMS": params,
+ "SLIDERS": conversions,
+ }
+
with open(oldfile, "r", encoding="utf-8") as infile, open(
newfile, "w", encoding="utf-8"
) as outfile:
@@ -87,18 +118,6 @@ def massage_output(oldfile, newfile, xml):
return
if seen_start:
- if "<<INLETS>>" in line:
- outfile.write(line.replace("<<INLETS>>", inlets))
- continue
-
- if "<<PARAMS>>" in line:
- outfile.write(line.replace("<<PARAMS>>", params))
- continue
-
- if "<<SLIDERS>>" in line:
- outfile.write(line.replace("<<SLIDERS>>", conversions))
- continue
-
if line.startswith("#ifdef __cplusplus"):
skip_ifdef = True
@@ -107,6 +126,10 @@ def massage_output(oldfile, newfile, xml):
skip_ifdef = False
continue
+ for key, value in replacements.items():
+ if "<<" + key + ">>" in line:
+ line = line.replace("<<" + key + ">>", value)
+
outfile.write(line)
else:
continue