Add DX7 graph pitch LFO lowering
This commit is contained in:
parent
64a326fa4f
commit
bfa70f9754
11 changed files with 129 additions and 28 deletions
|
|
@ -241,6 +241,30 @@ public static class Dx7SysEx
|
|||
return 1;
|
||||
}
|
||||
|
||||
public static float LfoFrequencyHz(Dx7Lfo lfo)
|
||||
{
|
||||
var speed = Math.Clamp(lfo.Speed, 0, 99) / 99f;
|
||||
return 0.1f + 40f * speed * speed;
|
||||
}
|
||||
|
||||
public static float LfoDelaySeconds(Dx7Lfo lfo) =>
|
||||
Math.Clamp(lfo.Delay, 0, 99) / 99f * 0.7f;
|
||||
|
||||
public static float PitchLfoDepth(Dx7Lfo lfo)
|
||||
{
|
||||
if (lfo.PitchModulationDepth <= 0 || lfo.PitchModulationSensitivity <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.Clamp(
|
||||
lfo.PitchModulationDepth / 99f *
|
||||
lfo.PitchModulationSensitivity / 7f *
|
||||
0.08f,
|
||||
0,
|
||||
0.08f);
|
||||
}
|
||||
|
||||
public static float OperatorFrequencyRatio(Dx7Operator op, int midiNote = 60, float baseFrequencyHz = 261.62558f)
|
||||
{
|
||||
if (op.FrequencyMode == Dx7FrequencyMode.Fixed)
|
||||
|
|
|
|||
|
|
@ -347,7 +347,16 @@ public static class FaustEmitter
|
|||
source.AppendLine($"{name}_note_freq = hslider(\"/{name}/note/frequency\", {F(graph.Note.FrequencyHz)}, 20, 20000, 0.01) : si.smoo;");
|
||||
source.AppendLine($"{name}_note_gate = button(\"/{name}/note/gate\");");
|
||||
}
|
||||
source.AppendLine($"{name}_freq = {graphNoteFreq};");
|
||||
var graphVibratoDepth = parameters.Expression($"{graphPath}/pitch/vibrato", graph.VibratoDepth);
|
||||
var graphVibratoHz = parameters.Expression($"{graphPath}/pitch/vibrato_hz", graph.VibratoHz);
|
||||
var graphVibratoDelay = parameters.Expression($"{graphPath}/pitch/vibrato_delay", graph.VibratoDelaySeconds);
|
||||
var hasGraphVibrato = graph.VibratoDepth > 0 && graph.VibratoHz > 0 ||
|
||||
parameters.IsBound($"{graphPath}/pitch/vibrato") ||
|
||||
parameters.IsBound($"{graphPath}/pitch/vibrato_hz");
|
||||
var graphPitchMod = hasGraphVibrato
|
||||
? $" * max(0.0, 1.0 + clip01(age / max(0.0001, {graphVibratoDelay})) * {graphVibratoDepth} * lfo_sin({graphVibratoHz}, 0.0))"
|
||||
: "";
|
||||
source.AppendLine($"{name}_freq = {graphNoteFreq}{graphPitchMod};");
|
||||
foreach (var op in ordered)
|
||||
{
|
||||
var opName = $"{name}_op_{op.Id}";
|
||||
|
|
|
|||
|
|
@ -156,7 +156,10 @@ public sealed record OperatorGraph(
|
|||
IReadOnlyList<OperatorEdge> Edges,
|
||||
IReadOnlyList<int> Carriers,
|
||||
Note Note = null!,
|
||||
float Gain = 0.2f)
|
||||
float Gain = 0.2f,
|
||||
float VibratoDepth = 0,
|
||||
float VibratoHz = 0,
|
||||
float VibratoDelaySeconds = 0)
|
||||
{
|
||||
public Note Note { get; init; } = Note ?? new();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -339,16 +339,19 @@ public static class PatchScript
|
|||
: operators.Select(op => op.Id).ToList();
|
||||
|
||||
AddValidatedOperatorGraph(line, new OperatorGraph(
|
||||
GetAny(fields, ["name", "n"], $"opgraph{graphIndex}"),
|
||||
GetBoundFloat(fields, line, 440, $"{graphPath}/freq", "freq", "frequency", "f"),
|
||||
operators,
|
||||
edges,
|
||||
carriers,
|
||||
new Note(
|
||||
Name: GetAny(fields, ["name", "n"], $"opgraph{graphIndex}"),
|
||||
FrequencyHz: GetBoundFloat(fields, line, 440, $"{graphPath}/freq", "freq", "frequency", "f"),
|
||||
Operators: operators,
|
||||
Edges: edges,
|
||||
Carriers: carriers,
|
||||
Note: new Note(
|
||||
GetBoundFloat(fields, line, 440, $"{graphPath}/note/frequency", "freq", "frequency", "f"),
|
||||
GetBoundFloat(fields, line, 0.1f, $"{graphPath}/note/gate", "gate", "hold", "duration"),
|
||||
ParseNoteSource(GetAny(fields, ["note_source", "source"], "oneshot"), line)),
|
||||
GetBoundFloat(fields, line, 0.2f, $"{graphPath}/gain", "gain", "g")));
|
||||
Gain: GetBoundFloat(fields, line, 0.2f, $"{graphPath}/gain", "gain", "g"),
|
||||
VibratoDepth: GetBoundFloat(fields, line, 0, $"{graphPath}/pitch/vibrato", "vibrato", "vib"),
|
||||
VibratoHz: GetBoundFloat(fields, line, 0, $"{graphPath}/pitch/vibrato_hz", "vibrato_hz", "vib_hz"),
|
||||
VibratoDelaySeconds: GetBoundFloat(fields, line, 0, $"{graphPath}/pitch/vibrato_delay", "vibrato_delay", "vib_delay")));
|
||||
}
|
||||
|
||||
private void StartOperatorGraph(IReadOnlyDictionary<string, string> fields, int line)
|
||||
|
|
@ -371,7 +374,10 @@ public static class PatchScript
|
|||
GetBoundFloat(fields, line, 440, $"{graphPath}/note/frequency", "freq", "frequency", "f"),
|
||||
GetBoundFloat(fields, line, 0.1f, $"{graphPath}/note/gate", "gate", "hold", "duration"),
|
||||
ParseNoteSource(GetAny(fields, ["note_source", "source"], "oneshot"), line)),
|
||||
GetBoundFloat(fields, line, 0.2f, $"{graphPath}/gain", "gain", "g"));
|
||||
GetBoundFloat(fields, line, 0.2f, $"{graphPath}/gain", "gain", "g"),
|
||||
GetBoundFloat(fields, line, 0, $"{graphPath}/pitch/vibrato", "vibrato", "vib"),
|
||||
GetBoundFloat(fields, line, 0, $"{graphPath}/pitch/vibrato_hz", "vibrato_hz", "vib_hz"),
|
||||
GetBoundFloat(fields, line, 0, $"{graphPath}/pitch/vibrato_delay", "vibrato_delay", "vib_delay"));
|
||||
}
|
||||
|
||||
private void AddOperator(IReadOnlyDictionary<string, string> fields, int line)
|
||||
|
|
@ -390,13 +396,13 @@ public static class PatchScript
|
|||
GetBoundFloat(fields, line, graph.Note.GateSeconds, $"{operatorPath}/note/gate", "gate", "hold", "duration"));
|
||||
|
||||
graph.Operators.Add(new OperatorNode(
|
||||
id,
|
||||
GetBoundFloat(fields, line, 1, $"{operatorPath}/ratio", "ratio", "r"),
|
||||
GetBoundFloat(fields, line, 1, $"{operatorPath}/level", "level", "l"),
|
||||
GetBoundFloat(fields, line, 0, $"{operatorPath}/feedback", "feedback", "fb"),
|
||||
graph.Note with { GateSeconds = envelopeSpec.GateSeconds },
|
||||
envelopeSpec.Envelope,
|
||||
envelopeSpec.RateLevelEnvelope));
|
||||
Id: id,
|
||||
Ratio: GetBoundFloat(fields, line, 1, $"{operatorPath}/ratio", "ratio", "r"),
|
||||
Level: GetBoundFloat(fields, line, 1, $"{operatorPath}/level", "level", "l"),
|
||||
Feedback: GetBoundFloat(fields, line, 0, $"{operatorPath}/feedback", "feedback", "fb"),
|
||||
Note: graph.Note with { GateSeconds = envelopeSpec.GateSeconds },
|
||||
Envelope: envelopeSpec.Envelope,
|
||||
RateLevelEnvelope: envelopeSpec.RateLevelEnvelope));
|
||||
}
|
||||
|
||||
private void AddOperatorRoute(IReadOnlyDictionary<string, string> fields, int line)
|
||||
|
|
@ -428,7 +434,10 @@ public static class PatchScript
|
|||
graph.Edges,
|
||||
graph.Carriers.Count > 0 ? graph.Carriers : graph.Operators.Select(op => op.Id).ToList(),
|
||||
graph.Note,
|
||||
graph.Gain));
|
||||
graph.Gain,
|
||||
graph.VibratoDepth,
|
||||
graph.VibratoHz,
|
||||
graph.VibratoDelaySeconds));
|
||||
}
|
||||
|
||||
private void AddValidatedOperatorGraph(int line, OperatorGraph graph)
|
||||
|
|
@ -549,12 +558,12 @@ public static class PatchScript
|
|||
}
|
||||
|
||||
return new OperatorNode(
|
||||
ParseInt(pieces[0], line),
|
||||
ParseFloat(pieces[1], line),
|
||||
ParseFloat(pieces[2], line),
|
||||
pieces.Length >= 4 ? ParseFloat(pieces[3], line) : 0,
|
||||
pieces.Length >= 6 ? new Note(GateSeconds: ParseFloat(pieces[4], line)) : new Note(),
|
||||
pieces.Length >= 6 ? new Envelope(ReleaseSeconds: ParseFloat(pieces[5], line)) : new Envelope());
|
||||
Id: ParseInt(pieces[0], line),
|
||||
Ratio: ParseFloat(pieces[1], line),
|
||||
Level: ParseFloat(pieces[2], line),
|
||||
Feedback: pieces.Length >= 4 ? ParseFloat(pieces[3], line) : 0,
|
||||
Note: pieces.Length >= 6 ? new Note(GateSeconds: ParseFloat(pieces[4], line)) : new Note(),
|
||||
Envelope: pieces.Length >= 6 ? new Envelope(ReleaseSeconds: ParseFloat(pieces[5], line)) : new Envelope());
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
|
@ -756,7 +765,10 @@ public static class PatchScript
|
|||
string Name,
|
||||
float FrequencyHz,
|
||||
Note Note,
|
||||
float Gain)
|
||||
float Gain,
|
||||
float VibratoDepth,
|
||||
float VibratoHz,
|
||||
float VibratoDelaySeconds)
|
||||
{
|
||||
public List<OperatorNode> Operators { get; } = [];
|
||||
public List<OperatorEdge> Edges { get; } = [];
|
||||
|
|
|
|||
Loading…
Reference in a new issue