Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Cleaning up SoundData to work better without Sfxr properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Nov 3, 2020
1 parent 8cae5c0 commit 9517cee
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 218 deletions.
1 change: 1 addition & 0 deletions PixelVision8.CoreDesktop.csproj
Expand Up @@ -74,6 +74,7 @@
<Compile Include="SDK\Engine\Chips\Audio\Sfxr\SfxrParams.cs" />
<Compile Include="SDK\Engine\Chips\Audio\Sfxr\SfxrSoundChip.cs" />
<Compile Include="SDK\Engine\Chips\Audio\Sfxr\SfxrSynthChannel.cs" />
<Compile Include="SDK\Engine\Chips\Audio\Sfxr\SfxSoundData.cs" />
<Compile Include="SDK\Engine\Chips\Audio\SoundChannel.cs" />
<Compile Include="SDK\Engine\Chips\Audio\SoundChip.cs" />
<Compile Include="SDK\Engine\Chips\Game\GameChip.cs" />
Expand Down
25 changes: 25 additions & 0 deletions PixelVision8.CoreDesktop.sln
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30621.155
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PixelVision8.CoreDesktop", "PixelVision8.CoreDesktop.csproj", "{0050BF23-F810-4F0D-A976-C808FC5AC642}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0050BF23-F810-4F0D-A976-C808FC5AC642}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0050BF23-F810-4F0D-A976-C808FC5AC642}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0050BF23-F810-4F0D-A976-C808FC5AC642}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0050BF23-F810-4F0D-A976-C808FC5AC642}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A813DE31-E6D9-4E91-B2D0-35D94BD401A2}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion SDK/Editor/Editors/GameEditor.cs
Expand Up @@ -1562,7 +1562,7 @@ public void NewSound(int id)
{
// var settings = new SfxrSynth().parameters;
// TODO I don't like that this is a static value on the SoundData class
((SfxrSoundChip)soundChip).UpdateSound(id, SoundData.DEFAULT_SOUND_PARAM); //settings.GetSettingsString());
soundChip.UpdateSound(id, ""); //settings.GetSettingsString());
}

/// <summary>
Expand Down
240 changes: 120 additions & 120 deletions SDK/Editor/Exporters/SfxrSoundExporter.cs
Expand Up @@ -18,126 +18,126 @@
// Shawn Rakowski - @shwany
//

using PixelVision8.Engine;
using PixelVision8.Engine.Chips;
using PixelVision8.Runner.Utils;
using System.Text;

namespace PixelVision8.Runner.Exporters
{
public class SfxrSoundExporter : AbstractExporter
{
private readonly IEngine targetEngine;
private StringBuilder sb;
private SfxrSoundChip _sfxrSoundChip;

public SfxrSoundExporter(string fileName, IEngine targetEngine) : base(fileName)
{
using PixelVision8.Engine;
using PixelVision8.Engine.Chips;
using PixelVision8.Runner.Utils;
using System.Text;

namespace PixelVision8.Runner.Exporters
{
public class SfxrSoundExporter : AbstractExporter
{
private readonly IEngine targetEngine;
private StringBuilder sb;
private SfxrSoundChip _sfxrSoundChip;

public SfxrSoundExporter(string fileName, IEngine targetEngine) : base(fileName)
{
this.targetEngine = targetEngine;

_sfxrSoundChip = targetEngine.SoundChip as SfxrSoundChip;

// CalculateSteps();
}

public override void CalculateSteps()
{
base.CalculateSteps();

// Create a new string builder
_steps.Add(CreateStringBuilder);


_steps.Add(SaveGameData);

// Save the final string builder
_steps.Add(CloseStringBuilder);
}

private void SaveGameData()
{
var soundChip = targetEngine.SoundChip;

sb.Append("\"version\":\"v2\",");
JsonUtil.GetLineBreak(sb, 1);

JsonUtil.indentLevel++;
sb.Append("\"sounds\": [");

var total = soundChip.TotalSounds;
for (var i = 0; i < total; i++)
{
var sound = _sfxrSoundChip.ReadSound(i);
// if (sound != null)
// {
JsonUtil.indentLevel++;


// {
// "name":"Melody",
// "settings":"0,.5,,.2,,.2,.3,.1266,,,,,,,,,,,,,,,,,,1,,,,,,"
// },


sb.Append("{");
JsonUtil.GetLineBreak(sb, 1);

sb.Append("\"name\":\"");
sb.Append(sound.name);
sb.Append("\",");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("\"settings\":");
sb.Append("\"" + sound.param + "\"");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("}");

// sb.Append(sound.ReadSettings());
if (i < total - 1) sb.Append(",");

JsonUtil.GetLineBreak(sb, 1);
JsonUtil.indentLevel--;
// }
}

JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb, 1);
sb.Append("]");

CurrentStep++;
}

private void CreateStringBuilder()
{
sb = new StringBuilder();

sb.Append("{");
JsonUtil.indentLevel++;

JsonUtil.GetLineBreak(sb);
sb.Append("\"SoundChip\":");

JsonUtil.GetLineBreak(sb);
sb.Append("{");
JsonUtil.GetLineBreak(sb, 1);

// JsonUtil.indentLevel++;

CurrentStep++;
}

private void CloseStringBuilder()
{
JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb);
sb.Append("}");

JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb, 1);
sb.Append("}");

bytes = Encoding.UTF8.GetBytes(sb.ToString());

CurrentStep++;
}
}
_sfxrSoundChip = targetEngine.SoundChip as SfxrSoundChip;

// CalculateSteps();
}

public override void CalculateSteps()
{
base.CalculateSteps();

// Create a new string builder
_steps.Add(CreateStringBuilder);


_steps.Add(SaveGameData);

// Save the final string builder
_steps.Add(CloseStringBuilder);
}

private void SaveGameData()
{
var soundChip = targetEngine.SoundChip;

sb.Append("\"version\":\"v2\",");
JsonUtil.GetLineBreak(sb, 1);

JsonUtil.indentLevel++;
sb.Append("\"sounds\": [");

var total = soundChip.TotalSounds;
for (var i = 0; i < total; i++)
{
var sound = _sfxrSoundChip.ReadSound(i);
// if (sound != null)
// {
JsonUtil.indentLevel++;


// {
// "name":"Melody",
// "settings":"0,.5,,.2,,.2,.3,.1266,,,,,,,,,,,,,,,,,,1,,,,,,"
// },


sb.Append("{");
JsonUtil.GetLineBreak(sb, 1);

sb.Append("\"name\":\"");
sb.Append(sound.name);
sb.Append("\",");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("\"settings\":");
sb.Append("\"" + sound.param + "\"");
JsonUtil.GetLineBreak(sb, 1);
sb.Append("}");

// sb.Append(sound.ReadSettings());
if (i < total - 1) sb.Append(",");

JsonUtil.GetLineBreak(sb, 1);
JsonUtil.indentLevel--;
// }
}

JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb, 1);
sb.Append("]");

CurrentStep++;
}

private void CreateStringBuilder()
{
sb = new StringBuilder();

sb.Append("{");
JsonUtil.indentLevel++;

JsonUtil.GetLineBreak(sb);
sb.Append("\"SoundChip\":");

JsonUtil.GetLineBreak(sb);
sb.Append("{");
JsonUtil.GetLineBreak(sb, 1);

// JsonUtil.indentLevel++;

CurrentStep++;
}

private void CloseStringBuilder()
{
JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb);
sb.Append("}");

JsonUtil.indentLevel--;
JsonUtil.GetLineBreak(sb, 1);
sb.Append("}");

bytes = Encoding.UTF8.GetBytes(sb.ToString());

CurrentStep++;
}
}
}

0 comments on commit 9517cee

Please sign in to comment.