Realtime editing of synth variables and outputs

This commit is contained in:
dexy 2022-01-28 19:15:59 +11:00
parent bc14a1fd22
commit 1371c0390e
3 changed files with 79 additions and 32 deletions

View File

@ -29,10 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RelForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RelForm));
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.RelPropertyGrid = new CodeWalker.WinForms.PropertyGridFix(); this.RelPropertyGrid = new CodeWalker.WinForms.PropertyGridFix();
this.MainTabControl = new System.Windows.Forms.TabControl(); this.MainTabControl = new System.Windows.Forms.TabControl();
this.XmlTabPage = new System.Windows.Forms.TabPage(); this.XmlTabPage = new System.Windows.Forms.TabPage();
@ -48,6 +48,7 @@
this.SearchButton = new System.Windows.Forms.Button(); this.SearchButton = new System.Windows.Forms.Button();
this.SearchResultsGrid = new CodeWalker.WinForms.PropertyGridFix(); this.SearchResultsGrid = new CodeWalker.WinForms.PropertyGridFix();
this.SynthsTabPage = new System.Windows.Forms.TabPage(); this.SynthsTabPage = new System.Windows.Forms.TabPage();
this.SynthStopButton = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.SynthVariablesTextBox = new System.Windows.Forms.TextBox(); this.SynthVariablesTextBox = new System.Windows.Forms.TextBox();
@ -78,7 +79,6 @@
this.wIPToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.wIPToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.OpenFileDialog = new System.Windows.Forms.OpenFileDialog(); this.OpenFileDialog = new System.Windows.Forms.OpenFileDialog();
this.SaveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.SaveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.SynthStopButton = new System.Windows.Forms.Button();
this.MainTabControl.SuspendLayout(); this.MainTabControl.SuspendLayout();
this.XmlTabPage.SuspendLayout(); this.XmlTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.XmlTextBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.XmlTextBox)).BeginInit();
@ -311,6 +311,18 @@
this.SynthsTabPage.Text = "Synths"; this.SynthsTabPage.Text = "Synths";
this.SynthsTabPage.UseVisualStyleBackColor = true; this.SynthsTabPage.UseVisualStyleBackColor = true;
// //
// SynthStopButton
//
this.SynthStopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.SynthStopButton.Enabled = false;
this.SynthStopButton.Location = new System.Drawing.Point(724, 2);
this.SynthStopButton.Name = "SynthStopButton";
this.SynthStopButton.Size = new System.Drawing.Size(104, 23);
this.SynthStopButton.TabIndex = 43;
this.SynthStopButton.Text = "Stop";
this.SynthStopButton.UseVisualStyleBackColor = true;
this.SynthStopButton.Click += new System.EventHandler(this.SynthStopButton_Click);
//
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
@ -336,6 +348,7 @@
this.SynthVariablesTextBox.Name = "SynthVariablesTextBox"; this.SynthVariablesTextBox.Name = "SynthVariablesTextBox";
this.SynthVariablesTextBox.Size = new System.Drawing.Size(293, 87); this.SynthVariablesTextBox.Size = new System.Drawing.Size(293, 87);
this.SynthVariablesTextBox.TabIndex = 40; this.SynthVariablesTextBox.TabIndex = 40;
this.SynthVariablesTextBox.TextChanged += new System.EventHandler(this.SynthVariablesTextBox_TextChanged);
// //
// SynthOutputsTextBox // SynthOutputsTextBox
// //
@ -343,23 +356,24 @@
this.SynthOutputsTextBox.Name = "SynthOutputsTextBox"; this.SynthOutputsTextBox.Name = "SynthOutputsTextBox";
this.SynthOutputsTextBox.Size = new System.Drawing.Size(293, 20); this.SynthOutputsTextBox.Size = new System.Drawing.Size(293, 20);
this.SynthOutputsTextBox.TabIndex = 39; this.SynthOutputsTextBox.TabIndex = 39;
this.SynthOutputsTextBox.TextChanged += new System.EventHandler(this.SynthOutputsTextBox_TextChanged);
// //
// SynthBufferChart // SynthBufferChart
// //
this.SynthBufferChart.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.SynthBufferChart.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
chartArea2.Name = "ChartArea1"; chartArea1.Name = "ChartArea1";
this.SynthBufferChart.ChartAreas.Add(chartArea2); this.SynthBufferChart.ChartAreas.Add(chartArea1);
legend2.Name = "Legend1"; legend1.Name = "Legend1";
this.SynthBufferChart.Legends.Add(legend2); this.SynthBufferChart.Legends.Add(legend1);
this.SynthBufferChart.Location = new System.Drawing.Point(363, 31); this.SynthBufferChart.Location = new System.Drawing.Point(363, 31);
this.SynthBufferChart.Name = "SynthBufferChart"; this.SynthBufferChart.Name = "SynthBufferChart";
series2.ChartArea = "ChartArea1"; series1.ChartArea = "ChartArea1";
series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
series2.IsXValueIndexed = true; series1.IsXValueIndexed = true;
series2.Legend = "Legend1"; series1.Legend = "Legend1";
series2.Name = "Buffer"; series1.Name = "Buffer";
this.SynthBufferChart.Series.Add(series2); this.SynthBufferChart.Series.Add(series1);
this.SynthBufferChart.Size = new System.Drawing.Size(460, 112); this.SynthBufferChart.Size = new System.Drawing.Size(460, 112);
this.SynthBufferChart.TabIndex = 38; this.SynthBufferChart.TabIndex = 38;
this.SynthBufferChart.Text = "chart1"; this.SynthBufferChart.Text = "chart1";
@ -613,18 +627,6 @@
// //
this.SaveFileDialog.Filter = "XML files|*.xml|All files|*.*"; this.SaveFileDialog.Filter = "XML files|*.xml|All files|*.*";
// //
// SynthStopButton
//
this.SynthStopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.SynthStopButton.Enabled = false;
this.SynthStopButton.Location = new System.Drawing.Point(724, 2);
this.SynthStopButton.Name = "SynthStopButton";
this.SynthStopButton.Size = new System.Drawing.Size(104, 23);
this.SynthStopButton.TabIndex = 43;
this.SynthStopButton.Text = "Stop";
this.SynthStopButton.UseVisualStyleBackColor = true;
this.SynthStopButton.Click += new System.EventHandler(this.SynthStopButton_Click);
//
// RelForm // RelForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -56,6 +56,9 @@ namespace CodeWalker.Forms
public RpfFileEntry rpfFileEntry { get; private set; } = null; public RpfFileEntry rpfFileEntry { get; private set; } = null;
private MetaFormat metaFormat = MetaFormat.XML; private MetaFormat metaFormat = MetaFormat.XML;
private bool loadingSynth = false;
private Dat10Synth currentSynth = null;
public RelForm(ExploreForm owner) public RelForm(ExploreForm owner)
{ {
@ -414,7 +417,15 @@ namespace CodeWalker.Forms
if (outputs.Length <= i) if (outputs.Length <= i)
break; break;
outputsIndices[i] = byte.Parse(outputs[i].Substring(1)); var output = "0";
if (outputs[i].Length > 1)
{
output = outputs[i].Substring(1);
}
if (byte.TryParse(output, out byte ind))
{
outputsIndices[i] = ind;
}
} }
return outputsIndices; return outputsIndices;
@ -429,8 +440,8 @@ namespace CodeWalker.Forms
var parts = variablesLines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var parts = variablesLines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
variables[i] = new Dat10SynthVariable variables[i] = new Dat10SynthVariable
{ {
Name = XmlMeta.GetHash(parts[0]), Name = XmlMeta.GetHash((parts.Length > 0) ? parts[0] : ""),
Value = FloatUtil.Parse(parts[1]), Value = FloatUtil.Parse((parts.Length > 1) ? parts[1] : ""),
}; };
} }
@ -448,7 +459,7 @@ namespace CodeWalker.Forms
if (error) if (error)
return null; return null;
return new Dat10Synth(CurrentFile) currentSynth = new Dat10Synth(CurrentFile)
{ {
BuffersCount = result.BuffersCount, BuffersCount = result.BuffersCount,
RegistersCount = result.RegistersCount, RegistersCount = result.RegistersCount,
@ -462,6 +473,8 @@ namespace CodeWalker.Forms
Variables = variables, Variables = variables,
RuntimeCost = 123 RuntimeCost = 123
}; };
return currentSynth;
} }
@ -648,6 +661,8 @@ namespace CodeWalker.Forms
return; return;
} }
loadingSynth = true;
SynthTextBox.Text = Dat10Synth.Disassemble(synth.Bytecode, synth.Constants, synth.Variables, false).Disassembly; SynthTextBox.Text = Dat10Synth.Disassemble(synth.Bytecode, synth.Constants, synth.Variables, false).Disassembly;
SynthTextBox.ClearUndo(); SynthTextBox.ClearUndo();
SynthAssemblySyntaxHighlight(SynthTextBox.Range); SynthAssemblySyntaxHighlight(SynthTextBox.Range);
@ -657,6 +672,10 @@ namespace CodeWalker.Forms
SynthOutputsTextBox.Clear(); SynthOutputsTextBox.Clear();
SynthOutputsTextBox.Text = string.Join(" ", synth.OutputsIndices.Take(synth.OutputsCount).Select(bufferIdx => $"B{bufferIdx}")); SynthOutputsTextBox.Text = string.Join(" ", synth.OutputsIndices.Take(synth.OutputsCount).Select(bufferIdx => $"B{bufferIdx}"));
currentSynth = synth;
loadingSynth = false;
} }
private void SynthTextBox_TextChangedDelayed(object sender, TextChangedEventArgs e) private void SynthTextBox_TextChangedDelayed(object sender, TextChangedEventArgs e)
@ -729,6 +748,7 @@ namespace CodeWalker.Forms
{ {
//for (int i = 0; i < buffersCopy.Length; i++) //for (int i = 0; i < buffersCopy.Length; i++)
int i = synthesizer.Synth.OutputsIndices[0]; int i = synthesizer.Synth.OutputsIndices[0];
if (i < SynthBufferChart.Series.Count)
{ {
var series = SynthBufferChart.Series[$"B{i}"]; var series = SynthBufferChart.Series[$"B{i}"];
series.Points.Clear(); series.Points.Clear();
@ -767,5 +787,23 @@ namespace CodeWalker.Forms
if (synthesizer != null) if (synthesizer != null)
synthesizer.Stop(); synthesizer.Stop();
} }
private void SynthVariablesTextBox_TextChanged(object sender, EventArgs e)
{
if (loadingSynth) return;
if (currentSynth == null) return;
currentSynth.Variables = ParseSynthVariables();
}
private void SynthOutputsTextBox_TextChanged(object sender, EventArgs e)
{
if (loadingSynth) return;
if (currentSynth == null) return;
currentSynth.OutputsIndices = ParseSynthOutputs();
}
} }
} }

View File

@ -91,7 +91,11 @@ namespace CodeWalker.Utils
} }
SynthesizeFrame(); SynthesizeFrame();
var audioDataStream = DataStream.Create(Buffers[Synth.OutputsIndices[0]], true, false);
var bufferIndex = Synth.OutputsIndices[0];
if ((bufferIndex < 0) || (bufferIndex >= Buffers.Length)) bufferIndex = 0;
var audioDataStream = DataStream.Create(Buffers[bufferIndex], true, false);
var audioBuffer = new AudioBuffer var audioBuffer = new AudioBuffer
{ {
Stream = audioDataStream, Stream = audioDataStream,
@ -694,7 +698,10 @@ namespace CodeWalker.Utils
} }
break; break;
case Dat10Synth.Opcode.READ_VARIABLE: case Dat10Synth.Opcode.READ_VARIABLE:
SetRegister(param[0], Synth.Variables[param[1].Value & 0xFF].Value); if ((param[1].Value & 0xFF) < Synth.Variables.Length)
{
SetRegister(param[0], Synth.Variables[param[1].Value & 0xFF]?.Value ?? 0);
}
break; break;
case Dat10Synth.Opcode.STOP: case Dat10Synth.Opcode.STOP:
stop = GetScalar(param[0]) >= 1.0f; stop = GetScalar(param[0]) >= 1.0f;