Add named layer DSL surface
This commit is contained in:
parent
8426ca50f4
commit
62ea9bee17
11 changed files with 188 additions and 27 deletions
|
|
@ -790,10 +790,13 @@ public static class BuiltInScripts
|
|||
vibrato=@/macro/motion
|
||||
vibrato_hz=5.5
|
||||
|
||||
voice freq=220 gain=0.16
|
||||
voice freq=440 gain=0.075
|
||||
voice freq=660 gain=0.045
|
||||
voice freq=880 gain=0.025
|
||||
layer name=body engine=add min_key=36 max_key=96 gain=0.16
|
||||
layer name=shine engine=add min_key=48 max_key=108 gain=0.045
|
||||
|
||||
voice layer=body freq=220
|
||||
voice layer=body freq=440 gain=0.075
|
||||
voice layer=shine freq=660
|
||||
voice layer=shine freq=880 gain=0.025
|
||||
""";
|
||||
|
||||
public const string ZynStylePadTexture = """
|
||||
|
|
@ -827,10 +830,14 @@ public static class BuiltInScripts
|
|||
lpf=0.18
|
||||
gain=0.05
|
||||
|
||||
voice freq=130.8128 gain=0.07 vibrato=@/macro/spread vibrato_hz=0.09
|
||||
voice freq=196 gain=0.052 vibrato=0.012 vibrato_hz=0.13
|
||||
voice freq=261.6256 gain=0.044 wave=triangle vibrato=0.009 vibrato_hz=0.11
|
||||
voice wave=noise freq=1800 gain=0.018 noise=0.82 attack=0.8 sustain=1.7 decay=1.1 lpf=0.36 hpf=0.22
|
||||
layer name=pad_low engine=pad min_key=36 max_key=84 gain=0.07 vibrato=@/macro/spread vibrato_hz=0.09
|
||||
layer name=pad_high engine=pad min_key=48 max_key=108 gain=0.044 vibrato=0.009 vibrato_hz=0.11
|
||||
layer name=air engine=add min_key=0 max_key=127 gain=0.018 wave=noise noise=0.82 attack=0.8 sustain=1.7 decay=1.1 lpf=0.36 hpf=0.22
|
||||
|
||||
voice layer=pad_low freq=130.8128
|
||||
voice layer=pad_low freq=196 gain=0.052 vibrato=0.012 vibrato_hz=0.13
|
||||
voice layer=pad_high freq=261.6256 wave=triangle
|
||||
voice layer=air freq=1800
|
||||
""";
|
||||
|
||||
public const string ZynStyleVocalLayer = """
|
||||
|
|
@ -861,27 +868,27 @@ public static class BuiltInScripts
|
|||
formant_mix=0.22
|
||||
gain=0.04
|
||||
|
||||
layer name=air engine=add min_key=48 max_key=108 gain=0.11 send=formant
|
||||
layer name=body engine=sub min_key=24 max_key=72 gain=0.075
|
||||
layer name=breath engine=add min_key=0 max_key=127 gain=0.018 wave=noise noise=0.75 hpf=0.58 lpf=0.62 send=formant
|
||||
|
||||
voice
|
||||
layer=air
|
||||
wave=saw
|
||||
freq=174.614
|
||||
gain=0.11
|
||||
formants=520:90:0.9,1080:150:1,2450:280:0.35
|
||||
formant_mix=@/macro/vowel
|
||||
|
||||
voice
|
||||
layer=body
|
||||
wave=triangle
|
||||
freq=87.307
|
||||
gain=0.075
|
||||
lpf=0.48
|
||||
drive=0.08
|
||||
|
||||
voice
|
||||
wave=noise
|
||||
layer=breath
|
||||
freq=2600
|
||||
gain=0.018
|
||||
noise=0.75
|
||||
hpf=0.58
|
||||
lpf=0.62
|
||||
formants=700:120:0.5,1600:220:0.6
|
||||
formant_mix=0.3
|
||||
""";
|
||||
|
|
|
|||
|
|
@ -186,6 +186,14 @@ public sealed record ReferenceSource(
|
|||
|
||||
public sealed record ReferenceFeature(string Name, string Value, string Notes = "");
|
||||
|
||||
public sealed record PatchLayer(
|
||||
string Name,
|
||||
string Engine = "",
|
||||
int? MinKey = null,
|
||||
int? MaxKey = null,
|
||||
float Gain = 1,
|
||||
string EffectSend = "");
|
||||
|
||||
public sealed record ReferencePatch(
|
||||
string Id,
|
||||
string Family,
|
||||
|
|
@ -199,6 +207,7 @@ public sealed record Repeat(float IntervalSeconds);
|
|||
|
||||
public sealed record Voice
|
||||
{
|
||||
public PatchLayer? Layer { get; init; }
|
||||
public Oscillator Oscillator { get; init; } = new();
|
||||
public Note Note { get; init; } = new();
|
||||
public Envelope Envelope { get; init; } = new();
|
||||
|
|
@ -217,6 +226,7 @@ public sealed record Voice
|
|||
public sealed record SynthPatch
|
||||
{
|
||||
public IReadOnlyList<Voice> Voices { get; init; } = Array.Empty<Voice>();
|
||||
public IReadOnlyList<PatchLayer> Layers { get; init; } = Array.Empty<PatchLayer>();
|
||||
public IReadOnlyList<OperatorGraph> OperatorGraphs { get; init; } = Array.Empty<OperatorGraph>();
|
||||
public IReadOnlyList<ControlLane> Controls { get; init; } = Array.Empty<ControlLane>();
|
||||
public IReadOnlyList<PatchParameter> Parameters { get; init; } = Array.Empty<PatchParameter>();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@ public static class PatchScript
|
|||
private readonly List<OperatorGraph> _operatorGraphs = [];
|
||||
private readonly List<PatchParameter> _parameters = [];
|
||||
private readonly List<ParameterBinding> _parameterBindings = [];
|
||||
private readonly List<PatchLayer> _layers = [];
|
||||
private readonly Dictionary<string, string> _defaults = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, Dictionary<string, string>> _layerDefaults = new(StringComparer.OrdinalIgnoreCase);
|
||||
private PendingOperatorGraph? _pendingOperatorGraph;
|
||||
|
||||
public List<Voice> Voices { get; } = [];
|
||||
|
|
@ -51,6 +53,7 @@ public static class PatchScript
|
|||
return new SynthPatch
|
||||
{
|
||||
Voices = Voices,
|
||||
Layers = _layers,
|
||||
OperatorGraphs = _operatorGraphs,
|
||||
Controls = _controls,
|
||||
Parameters = _parameters,
|
||||
|
|
@ -90,6 +93,10 @@ public static class PatchScript
|
|||
var name = Required(fields, "name", line);
|
||||
_templates[name] = Without(fields, "name");
|
||||
break;
|
||||
case "layer":
|
||||
FlushPendingOperatorGraph();
|
||||
AddLayer(fields, line);
|
||||
break;
|
||||
case "voice":
|
||||
FlushPendingOperatorGraph();
|
||||
Voices.Add(ParseVoice(ExpandVoiceFields(fields, line), Voices.Count, line));
|
||||
|
|
@ -130,6 +137,14 @@ public static class PatchScript
|
|||
private Dictionary<string, string> ExpandVoiceFields(Dictionary<string, string> fields, int line)
|
||||
{
|
||||
var expanded = new Dictionary<string, string>(_defaults, StringComparer.OrdinalIgnoreCase);
|
||||
if (TryGetAny(fields, ["layer"], out var layerName))
|
||||
{
|
||||
if (!_layerDefaults.TryGetValue(layerName, out var layer))
|
||||
{
|
||||
throw new PatchScriptException(line, $"unknown layer `{layerName}`");
|
||||
}
|
||||
Merge(expanded, layer);
|
||||
}
|
||||
if (TryGetAny(fields, ["use", "u"], out var templateName))
|
||||
{
|
||||
foreach (var name in templateName.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
|
|
@ -145,6 +160,43 @@ public static class PatchScript
|
|||
return expanded;
|
||||
}
|
||||
|
||||
private void AddLayer(IReadOnlyDictionary<string, string> fields, int line)
|
||||
{
|
||||
var name = Required(fields, "name", line);
|
||||
if (_layers.Any(layer => layer.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
throw new PatchScriptException(line, $"duplicate layer `{name}`");
|
||||
}
|
||||
|
||||
var layer = new PatchLayer(
|
||||
name,
|
||||
GetAny(fields, ["engine", "e"], ""),
|
||||
TryGetAny(fields, ["min_key", "key_min", "lo"], out var minKey) ? ParseInt(minKey, line) : null,
|
||||
TryGetAny(fields, ["max_key", "key_max", "hi"], out var maxKey) ? ParseInt(maxKey, line) : null,
|
||||
GetBoundFloat(fields, line, 1, $"/layers/{_layers.Count}/gain", "gain", "g"),
|
||||
GetAny(fields, ["send", "effect", "fx"], ""));
|
||||
if (layer is { MinKey: { } min, MaxKey: { } max } && min > max)
|
||||
{
|
||||
throw new PatchScriptException(line, "layer min_key must be less than or equal to max_key");
|
||||
}
|
||||
|
||||
_layers.Add(layer);
|
||||
_layerDefaults[name] = LayerVoiceFields(layer, Without(fields, "name", "engine", "e", "min_key", "key_min", "lo", "max_key", "key_max", "hi", "send", "effect", "fx"));
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> LayerVoiceFields(PatchLayer layer, IReadOnlyDictionary<string, string> fields)
|
||||
{
|
||||
var result = new Dictionary<string, string>(fields, StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["layer"] = layer.Name
|
||||
};
|
||||
if (!result.ContainsKey("gain"))
|
||||
{
|
||||
result["gain"] = F(layer.Gain);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ApplyPatch(IReadOnlyDictionary<string, string> fields, int line)
|
||||
{
|
||||
if (TryGetAny(fields, ["gain", "g"], out var gain)) Gain = ParseBoundFloat(gain, line, Gain, "/patch/gain");
|
||||
|
|
@ -230,6 +282,9 @@ public static class PatchScript
|
|||
|
||||
return new Voice
|
||||
{
|
||||
Layer = TryGetAny(fields, ["layer"], out var layerName)
|
||||
? _layers.First(layer => layer.Name.Equals(layerName, StringComparison.OrdinalIgnoreCase))
|
||||
: null,
|
||||
Oscillator = new Oscillator(
|
||||
waveform,
|
||||
frequency,
|
||||
|
|
@ -845,6 +900,7 @@ public static class PatchScript
|
|||
"p" or "patch" or "instrument" => "patch",
|
||||
"d" or "default" or "defaults" => "defaults",
|
||||
"def" or "t" or "template" => "template",
|
||||
"layer" or "kit" => "layer",
|
||||
"v" or "voice" => "voice",
|
||||
"opgraph" or "ops" or "operators" => "opgraph",
|
||||
"operator" or "op" => "operator",
|
||||
|
|
@ -959,6 +1015,9 @@ public static class PatchScript
|
|||
? parsed
|
||||
: throw new PatchScriptException(line, $"bad number `{value}`");
|
||||
|
||||
private static string F(float value) =>
|
||||
value.ToString("0.######", CultureInfo.InvariantCulture);
|
||||
|
||||
private static float PunchGain(float value) => 1 + Math.Max(0, Math.Clamp(value, -1, 1));
|
||||
|
||||
private static int ParseInt(string value, int line) =>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public static class ReferenceRebuildCatalog
|
|||
BuiltInScripts.ZynStyleAdditiveLead,
|
||||
[
|
||||
new("engine_add", "1", "Represented as explicit additive sine partial voices."),
|
||||
new("named_layers", "body,shine", "Layer declarations group partial voices under reusable ADD engine intent."),
|
||||
new("partial_voice_count", "4", "The additive shape is represented as four explicit Aquarium partial voices."),
|
||||
new("envelope_count", "2", "Amplitude and pitch contour pressure maps to ADSR plus vibrato in the current patch surface."),
|
||||
new("lfo_count", "1", "The fixture's amplitude/frequency motion is represented as patch-level vibrato/macro motion.")
|
||||
|
|
@ -39,6 +40,7 @@ public static class ReferenceRebuildCatalog
|
|||
BuiltInScripts.ZynStylePadTexture,
|
||||
[
|
||||
new("engine_pad", "1", "Approximated as slow layered oscillators plus an air/noise layer."),
|
||||
new("named_layers", "pad_low,pad_high,air", "Layer declarations separate PAD body from air/noise texture."),
|
||||
new("filter_count", "1", "Represented with low-pass/high-pass field sites."),
|
||||
new("free_envelope_count", "1", "Approximated with slow ADSR timing and macro spread."),
|
||||
new("slow_modulation", "patch_lfo", "The rebuild adds slow patch modulation because PAD texture wants motion even though the minimal fixture only marks PAD/filter/free-envelope pressure.")
|
||||
|
|
@ -58,6 +60,7 @@ public static class ReferenceRebuildCatalog
|
|||
new("engine_add", "1", "The air/formant layer is represented as a formant-filtered oscillator voice."),
|
||||
new("engine_sub", "1", "The body layer is represented as a lower triangle voice."),
|
||||
new("layered_instrument", "yes", "Multiple Zyn kit items map to multiple Aquarium voices."),
|
||||
new("named_layers", "air,body,breath", "Layer declarations preserve source identity before voice expansion."),
|
||||
new("formant_filter_count", "1", "Represented with Aquarium formant filters and a vowel macro."),
|
||||
new("effect_count", "1", "Approximated with local drive/soft clipping rather than a Zyn effect slot.")
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue