AquaSynth/tools/AquaLower/Program.cs
Aqua 39843ae95c Add static in-browser playground for AquaSynth patches
tools/AquaLower lowers .aqua to Faust (FaustEmitter.EmitScript); tools/aqua-playground compiles
the lowered Faust to wasm with @grame/faustwasm in the page and plays it through an AudioWorklet,
with sliders from the DSP's UI and the Faust source shown. Thruster plus 41 .aqua patches.
Headless node test compiles and renders every patch (non-silent, finite).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-04 13:38:49 +00:00

35 lines
1.7 KiB
C#

using System.Text.Json;
using AquaSynth.Dsl;
// Lowers .aqua patches to Faust source for the static playground (tools/aqua-playground).
// usage: AquaLower <outDir> <patchesRoot> <name>=<relative .aqua or .dsp path> ...
// A .aqua entry goes through FaustEmitter.EmitScript, the same lowering the daemon uses; a .dsp entry
// (the thruster) is already Faust and is copied verbatim. Writes <outDir>/<name>.dsp, and
// catalog.json for the browser (the one non-CultNet xeno at this boundary).
if (args.Length < 3) { Console.Error.WriteLine("usage: AquaLower <outDir> <patchesRoot> <name>=<path> ..."); return 2; }
var outDir = Path.GetFullPath(args[0]);
var root = Path.GetFullPath(args[1]);
Directory.CreateDirectory(outDir);
var entries = new List<object>();
foreach (var spec in args.Skip(2))
{
var eq = spec.IndexOf('=');
var name = spec[..eq];
var rel = spec[(eq + 1)..];
var path = Path.Combine(root, rel);
var text = File.ReadAllText(path);
string source;
var warnings = new List<string>();
if (path.EndsWith(".aqua", StringComparison.Ordinal))
{
var export = FaustEmitter.EmitScript(text, new FaustExportOptions(name));
source = export.Source;
warnings.AddRange(export.Warnings);
}
else source = text;
File.WriteAllText(Path.Combine(outDir, name + ".dsp"), source);
entries.Add(new { name, origin = rel.Replace('\\', '/'), kind = path.EndsWith(".aqua", StringComparison.Ordinal) ? "aqua" : "faust", dsp = name + ".dsp", warnings });
Console.WriteLine($"{name}: {source.Length} chars from {rel}, {warnings.Count} warnings");
}
File.WriteAllText(Path.Combine(outDir, "catalog.json"), JsonSerializer.Serialize(entries, new JsonSerializerOptions { WriteIndented = true }));
return 0;