Persist A/V settings to disk properly (resolves #1226)

This commit is contained in:
YoshiRulz 2023-03-25 22:36:50 +10:00
parent 10423abdf9
commit 32d2f23117
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 28 additions and 50 deletions

View File

@ -276,6 +276,9 @@ namespace BizHawk.Client.Common
public int GifWriterDelay { get; set; } = -1; public int GifWriterDelay { get; set; } = -1;
public bool VideoWriterAudioSync { get; set; } = true; public bool VideoWriterAudioSync { get; set; } = true;
[JsonIgnore]
public bool VideoWriterAudioSyncEffective;
// Emulation core settings // Emulation core settings
internal Dictionary<string, JToken> CoreSettings { get; set; } = new Dictionary<string, JToken>(); internal Dictionary<string, JToken> CoreSettings { get; set; } = new Dictionary<string, JToken>();
internal Dictionary<string, JToken> CoreSyncSettings { get; set; } = new Dictionary<string, JToken>(); internal Dictionary<string, JToken> CoreSyncSettings { get; set; } = new Dictionary<string, JToken>();
@ -368,5 +371,9 @@ namespace BizHawk.Client.Common
public bool RASoundEffects { get; set; } = true; public bool RASoundEffects { get; set; } = true;
public bool RAAllowUnofficialCheevos { get; set; } public bool RAAllowUnofficialCheevos { get; set; }
public bool RAAutostart { get; set; } public bool RAAutostart { get; set; }
public bool AVWriterPad { get; set; } = false;
public (int Width, int Height) AVWriterResize { get; set; } = (0, 0);
} }
} }

View File

@ -61,15 +61,15 @@ namespace BizHawk.Client.EmuHawk
IEnumerable<VideoWriterInfo> list, IEnumerable<VideoWriterInfo> list,
T owner, T owner,
IEmulator emulator, IEmulator emulator,
Config config, Config config)
out int resizeW,
out int resizeH,
out bool pad,
ref bool audioSync)
where T : IMainFormForTools, IDialogParent where T : IMainFormForTools, IDialogParent
{ {
var dlg = new VideoWriterChooserForm(owner, emulator, config) var dlg = new VideoWriterChooserForm(owner, emulator, config)
{ {
checkBoxASync = { Checked = config.VideoWriterAudioSyncEffective },
checkBoxPad = { Checked = config.AVWriterPad },
numericTextBoxH = { Text = Math.Max(0, config.AVWriterResize.Height).ToString() },
numericTextBoxW = { Text = Math.Max(0, config.AVWriterResize.Width).ToString() },
labelDescriptionBody = { Text = "" } labelDescriptionBody = { Text = "" }
}; };
@ -95,8 +95,6 @@ namespace BizHawk.Client.EmuHawk
c.Enabled = false; c.Enabled = false;
} }
dlg.checkBoxASync.Checked = audioSync;
IVideoWriter ret = null; IVideoWriter ret = null;
if (owner.ShowDialogAsChild(dlg).IsOk() if (owner.ShowDialogAsChild(dlg).IsOk()
&& dlg.listBox1.SelectedIndex is not -1) && dlg.listBox1.SelectedIndex is not -1)
@ -106,20 +104,14 @@ namespace BizHawk.Client.EmuHawk
config.VideoWriter = vwi.Attribs.ShortName; config.VideoWriter = vwi.Attribs.ShortName;
} }
if (ret != null && dlg.checkBoxResize.Checked) if (ret is not null)
{ {
resizeW = dlg.numericTextBoxW.IntValue; config.AVWriterResize = dlg.checkBoxResize.Checked
resizeH = dlg.numericTextBoxH.IntValue; ? (dlg.numericTextBoxW.IntValue, dlg.numericTextBoxH.IntValue)
: (-1, -1);
config.AVWriterPad = dlg.checkBoxPad.Checked;
config.VideoWriterAudioSyncEffective = config.VideoWriterAudioSync = dlg.checkBoxASync.Checked;
} }
else
{
resizeW = -1;
resizeH = -1;
}
pad = dlg.checkBoxPad.Checked;
audioSync = dlg.checkBoxASync.Checked;
dlg.Dispose(); dlg.Dispose();
return ret; return ret;
} }

View File

@ -606,11 +606,7 @@ namespace BizHawk.Client.EmuHawk
LoadMostRecentROM(); LoadMostRecentROM();
} }
if (_argParser.audiosync.HasValue) Config.VideoWriterAudioSyncEffective = _argParser.audiosync ?? Config.VideoWriterAudioSync;
{
Config.VideoWriterAudioSync = _argParser.audiosync.Value;
}
_autoDumpLength = _argParser._autoDumpLength; _autoDumpLength = _argParser._autoDumpLength;
if (_argParser.cmdMovie != null) if (_argParser.cmdMovie != null)
{ {
@ -1705,10 +1701,6 @@ namespace BizHawk.Client.EmuHawk
private ISoundProvider _aviSoundInputAsync; // Note: This sound provider must be in async mode! private ISoundProvider _aviSoundInputAsync; // Note: This sound provider must be in async mode!
private SimpleSyncSoundProvider _dumpProxy; // an audio proxy used for dumping private SimpleSyncSoundProvider _dumpProxy; // an audio proxy used for dumping
private bool _dumpaudiosync; // set true to for experimental AV dumping
private int _avwriterResizew;
private int _avwriterResizeh;
private bool _avwriterpad;
private bool _windowClosedAndSafeToExitProcess; private bool _windowClosedAndSafeToExitProcess;
private int _exitCode; private int _exitCode;
@ -3358,7 +3350,6 @@ namespace BizHawk.Client.EmuHawk
videoWriterName = Config.VideoWriter; videoWriterName = Config.VideoWriter;
} }
_dumpaudiosync = Config.VideoWriterAudioSync;
if (unattended && !string.IsNullOrEmpty(videoWriterName)) if (unattended && !string.IsNullOrEmpty(videoWriterName))
{ {
aw = VideoWriterInventory.GetVideoWriter(videoWriterName, this); aw = VideoWriterInventory.GetVideoWriter(videoWriterName, this);
@ -3369,11 +3360,7 @@ namespace BizHawk.Client.EmuHawk
VideoWriterInventory.GetAllWriters(), VideoWriterInventory.GetAllWriters(),
this, this,
Emulator, Emulator,
Config, Config);
out _avwriterResizew,
out _avwriterResizeh,
out _avwriterpad,
ref _dumpaudiosync);
} }
if (aw == null) if (aw == null)
@ -3392,19 +3379,11 @@ namespace BizHawk.Client.EmuHawk
const bool usingAvi = false; const bool usingAvi = false;
#endif #endif
if (_dumpaudiosync) aw = Config.VideoWriterAudioSyncEffective ? new VideoStretcher(aw) : new AudioStretcher(aw);
{
aw = new VideoStretcher(aw);
}
else
{
aw = new AudioStretcher(aw);
}
aw.SetMovieParameters(Emulator.VsyncNumerator(), Emulator.VsyncDenominator()); aw.SetMovieParameters(Emulator.VsyncNumerator(), Emulator.VsyncDenominator());
if (_avwriterResizew > 0 && _avwriterResizeh > 0) if (Config.AVWriterResize.Width > 0 && Config.AVWriterResize.Height > 0)
{ {
aw.SetVideoParameters(_avwriterResizew, _avwriterResizeh); aw.SetVideoParameters(Config.AVWriterResize.Width, Config.AVWriterResize.Height);
} }
else else
{ {
@ -3492,7 +3471,7 @@ namespace BizHawk.Client.EmuHawk
throw; throw;
} }
if (_dumpaudiosync) if (Config.VideoWriterAudioSyncEffective)
{ {
_currentSoundProvider.SetSyncMode(SyncSoundMode.Sync); _currentSoundProvider.SetSyncMode(SyncSoundMode.Sync);
} }
@ -3567,7 +3546,7 @@ namespace BizHawk.Client.EmuHawk
{ {
IVideoProvider output; IVideoProvider output;
IDisposable disposableOutput = null; IDisposable disposableOutput = null;
if (_avwriterResizew > 0 && _avwriterResizeh > 0) if (Config.AVWriterResize.Width > 0 && Config.AVWriterResize.Height > 0)
{ {
BitmapBuffer bbIn = null; BitmapBuffer bbIn = null;
Bitmap bmpIn = null; Bitmap bmpIn = null;
@ -3579,11 +3558,11 @@ namespace BizHawk.Client.EmuHawk
bbIn.DiscardAlpha(); bbIn.DiscardAlpha();
var bmpOut = new Bitmap(_avwriterResizew, _avwriterResizeh, PixelFormat.Format32bppArgb); Bitmap bmpOut = new(width: Config.AVWriterResize.Width, height: Config.AVWriterResize.Height, PixelFormat.Format32bppArgb);
bmpIn = bbIn.ToSysdrawingBitmap(); bmpIn = bbIn.ToSysdrawingBitmap();
using (var g = Graphics.FromImage(bmpOut)) using (var g = Graphics.FromImage(bmpOut))
{ {
if (_avwriterpad) if (Config.AVWriterPad)
{ {
g.Clear(Color.FromArgb(_currentVideoProvider.BackgroundColor)); g.Clear(Color.FromArgb(_currentVideoProvider.BackgroundColor));
g.DrawImageUnscaled(bmpIn, (bmpOut.Width - bmpIn.Width) / 2, (bmpOut.Height - bmpIn.Height) / 2); g.DrawImageUnscaled(bmpIn, (bmpOut.Width - bmpIn.Width) / 2, (bmpOut.Height - bmpIn.Height) / 2);
@ -3627,7 +3606,7 @@ namespace BizHawk.Client.EmuHawk
short[] samp; short[] samp;
int nsamp; int nsamp;
if (_dumpaudiosync) if (Config.VideoWriterAudioSyncEffective)
{ {
((VideoStretcher) _currAviWriter).DumpAV(output, _currentSoundProvider, out samp, out nsamp); ((VideoStretcher) _currAviWriter).DumpAV(output, _currentSoundProvider, out samp, out nsamp);
} }