pass Config around to various AV writer and form classes, instead of using GlobalWin.Config

This commit is contained in:
adelikat 2020-11-28 13:57:40 -06:00
parent 84002f1232
commit bdf1838ac8
15 changed files with 86 additions and 77 deletions

View File

@ -1,6 +1,6 @@
using System;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
@ -213,9 +213,9 @@ namespace BizHawk.Client.EmuHawk
W.SetVideoCodecToken(token);
}
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
W.SetDefaultVideoCodecToken();
W.SetDefaultVideoCodecToken(config);
}
public void OpenFile(string baseName)
@ -243,9 +243,9 @@ namespace BizHawk.Client.EmuHawk
W.AddSamples(samples);
}
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
return W.AcquireVideoCodecToken(hwnd);
return W.AcquireVideoCodecToken(hwnd, config);
}
public void SetMovieParameters(int fpsNum, int fpsDen)

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Emulation.Common;
@ -257,7 +258,7 @@ namespace BizHawk.Client.EmuHawk
/// Acquires a video codec configuration from the user. you may save it for future use, but you must dispose of it when you're done with it.
/// returns null if the user canceled the dialog
/// </summary>
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
var tempParams = new Parameters
{
@ -274,7 +275,9 @@ namespace BizHawk.Client.EmuHawk
File.Delete(tempfile);
tempfile = Path.ChangeExtension(tempfile, "avi");
temp.OpenFile(tempfile, tempParams, null);
CodecToken token = (CodecToken)temp.AcquireVideoCodecToken(hwnd.Handle, _currVideoCodecToken);
var ret = temp.AcquireVideoCodecToken(hwnd.Handle, _currVideoCodecToken);
CodecToken token = (CodecToken)ret;
config.AviCodecToken = token?.Serialize();
temp.CloseFile();
File.Delete(tempfile);
return token;
@ -733,8 +736,6 @@ namespace BizHawk.Client.EmuHawk
if (result)
{
// save to config and return it
GlobalWin.Config.AviCodecToken = ret.Serialize();
return ret;
}
@ -963,15 +964,10 @@ namespace BizHawk.Client.EmuHawk
}
/// <exception cref="Exception">no default codec token in config</exception>
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
CodecToken ct = CodecToken.DeSerialize(GlobalWin.Config.AviCodecToken);
if (ct == null)
{
throw new Exception($"No default {nameof(GlobalWin.Config.AviCodecToken)} in config!");
}
_currVideoCodecToken = ct;
var ct = CodecToken.DeSerialize(config.AviCodecToken);
_currVideoCodecToken = ct ?? throw new Exception($"No default {nameof(config.AviCodecToken)} in config!");
}
public string DesiredExtension()

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Common.PathExtensions;
using BizHawk.Emulation.Common;
@ -206,16 +207,19 @@ namespace BizHawk.Client.EmuHawk
//ffmpeg.StandardInput.BaseStream.Write(b, 0, b.Length);
}
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
if (new FFmpegService().QueryServiceAvailable())
return FFmpegWriterForm.DoFFmpegWriterDlg(hwnd);
else
{
FFmpegDownloaderForm.Run(hwnd);
if (new FFmpegService().QueryServiceAvailable())
return FFmpegWriterForm.DoFFmpegWriterDlg(hwnd);
return FFmpegWriterForm.DoFFmpegWriterDlg(hwnd, config);
}
FFmpegDownloaderForm.Run(hwnd);
if (new FFmpegService().QueryServiceAvailable())
{
return FFmpegWriterForm.DoFFmpegWriterDlg(hwnd, config);
}
return null;
}
@ -317,9 +321,9 @@ namespace BizHawk.Client.EmuHawk
return _token.Extension;
}
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
_token = FFmpegWriterForm.FormatPreset.GetDefaultPreset();
_token = FFmpegWriterForm.FormatPreset.GetDefaultPreset(config.FFmpegFormat);
}
public bool UsesAudio => true;

View File

@ -1,5 +1,6 @@
using System;
using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
@ -75,13 +76,13 @@ namespace BizHawk.Client.EmuHawk
/// <summary>
/// get the default format preset (from config files)
/// </summary>
public static FormatPreset GetDefaultPreset()
public static FormatPreset GetDefaultPreset(string ffmpegFormat)
{
FormatPreset[] fps = GetPresets();
foreach (var fp in fps)
{
if (fp.ToString() == GlobalWin.Config.FFmpegFormat)
if (fp.ToString() == ffmpegFormat)
{
if (fp.Custom)
{
@ -148,12 +149,12 @@ namespace BizHawk.Client.EmuHawk
/// <summary>
/// return a FormatPreset corresponding to the user's choice
/// </summary>
public static FormatPreset DoFFmpegWriterDlg(IWin32Window owner)
public static FormatPreset DoFFmpegWriterDlg(IWin32Window owner, Config config)
{
FFmpegWriterForm dlg = new FFmpegWriterForm();
dlg.listBox1.Items.AddRange(FormatPreset.GetPresets());
int i = dlg.listBox1.FindStringExact(GlobalWin.Config.FFmpegFormat);
int i = dlg.listBox1.FindStringExact(config.FFmpegFormat);
if (i != ListBox.NoMatches)
{
dlg.listBox1.SelectedIndex = i;
@ -169,11 +170,11 @@ namespace BizHawk.Client.EmuHawk
else
{
ret = (FormatPreset)dlg.listBox1.SelectedItem;
GlobalWin.Config.FFmpegFormat = ret.ToString();
config.FFmpegFormat = ret.ToString();
if (ret.Custom)
{
ret.Commandline =
GlobalWin.Config.FFmpegCustomCommand =
config.FFmpegCustomCommand =
dlg.textBox1.Text;
ret.DeduceFormat(ret.Commandline);

View File

@ -1,6 +1,9 @@
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
@ -58,12 +61,12 @@ namespace BizHawk.Client.EmuHawk
}
}
public static GifToken LoadFromConfig()
public static GifToken LoadFromConfig(Config config)
{
return new GifToken(0, 0)
{
Frameskip = GlobalWin.Config.GifWriterFrameskip,
FrameDelay = GlobalWin.Config.GifWriterDelay
Frameskip = config.GifWriterFrameskip,
FrameDelay = config.GifWriterDelay
};
}
@ -94,9 +97,9 @@ namespace BizHawk.Client.EmuHawk
}
}
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
_token = GifToken.LoadFromConfig();
_token = GifToken.LoadFromConfig(config);
CalcDelay();
}
@ -192,9 +195,9 @@ namespace BizHawk.Client.EmuHawk
// ignored
}
public IDisposable AcquireVideoCodecToken(System.Windows.Forms.IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
return GifWriterForm.DoTokenForm(hwnd);
return GifWriterForm.DoTokenForm(hwnd, config);
}
private void CalcDelay()

View File

@ -1,5 +1,6 @@
using System;
using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
@ -10,22 +11,22 @@ namespace BizHawk.Client.EmuHawk
InitializeComponent();
}
public static GifWriter.GifToken DoTokenForm(IWin32Window parent)
public static GifWriter.GifToken DoTokenForm(IWin32Window parent, Config config)
{
using var dlg = new GifWriterForm
{
numericUpDown1 = { Value = GlobalWin.Config.GifWriterFrameskip },
numericUpDown2 = { Value = GlobalWin.Config.GifWriterDelay }
numericUpDown1 = { Value = config.GifWriterFrameskip },
numericUpDown2 = { Value = config.GifWriterDelay }
};
dlg.NumericUpDown2_ValueChanged(null, null);
var result = dlg.ShowDialog(parent);
if (result.IsOk())
{
GlobalWin.Config.GifWriterFrameskip = (int)dlg.numericUpDown1.Value;
GlobalWin.Config.GifWriterDelay = (int)dlg.numericUpDown2.Value;
config.GifWriterFrameskip = (int)dlg.numericUpDown1.Value;
config.GifWriterDelay = (int)dlg.numericUpDown2.Value;
return GifWriter.GifToken.LoadFromConfig();
return GifWriter.GifToken.LoadFromConfig(config);
}
return null;

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using BizHawk.Common;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
@ -16,7 +16,7 @@ namespace BizHawk.Client.EmuHawk
/// <summary>
/// sets to a default video codec token without calling any UI - for automated dumping
/// </summary>
void SetDefaultVideoCodecToken();
void SetDefaultVideoCodecToken(Config config);
/// <summary>
/// Returns whether this VideoWriter dumps audio
@ -64,7 +64,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
/// <param name="hwnd">hwnd to attach to if the user is shown config dialog</param>
/// <returns>codec token, dispose of it when you're done with it</returns>
IDisposable AcquireVideoCodecToken(System.Windows.Forms.IWin32Window hwnd);
IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config);
/// <summary>
/// set framerate to fpsNum/fpsDen (assumed to be unchanging over the life of the stream)

View File

@ -4,6 +4,7 @@ using System.Drawing.Imaging;
using System.Windows.Forms;
using BizHawk.Bizware.BizwareGL;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
@ -21,7 +22,7 @@ namespace BizHawk.Client.EmuHawk
{
}
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
}
@ -72,7 +73,7 @@ namespace BizHawk.Client.EmuHawk
}
}
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
return new CodecToken();
}

View File

@ -5,7 +5,7 @@ using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using BizHawk.Client.Common;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.Zip.Compression;
@ -529,20 +529,20 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
/// <param name="hwnd">hwnd to attach to if the user is shown config dialog</param>
/// <returns>codec token, dispose of it when you're done with it</returns>
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
var ret = new CodecToken();
// load from config and sanitize
int t = Math.Min(Math.Max(GlobalWin.Config.JmdThreads, 1), 6);
int t = Math.Min(Math.Max(config.JmdThreads, 1), 6);
int c = Math.Min(Math.Max(GlobalWin.Config.JmdCompression, Deflater.NO_COMPRESSION), Deflater.BEST_COMPRESSION);
int c = Math.Min(Math.Max(config.JmdCompression, Deflater.NO_COMPRESSION), Deflater.BEST_COMPRESSION);
if (!JmdForm.DoCompressionDlg(ref t, ref c, 1, 6, Deflater.NO_COMPRESSION, Deflater.BEST_COMPRESSION, hwnd))
return null;
GlobalWin.Config.JmdThreads = ret.NumThreads = t;
GlobalWin.Config.JmdCompression = ret.CompressionLevel = c;
config.JmdThreads = ret.NumThreads = t;
config.JmdCompression = ret.CompressionLevel = c;
return ret;
}
@ -778,14 +778,14 @@ namespace BizHawk.Client.EmuHawk
public string DesiredExtension() => "jmd";
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
CodecToken ct = new CodecToken();
// load from config and sanitize
int t = Math.Min(Math.Max(GlobalWin.Config.JmdThreads, 1), 6);
int t = Math.Min(Math.Max(config.JmdThreads, 1), 6);
int c = Math.Min(Math.Max(GlobalWin.Config.JmdCompression, Deflater.NO_COMPRESSION), Deflater.BEST_COMPRESSION);
int c = Math.Min(Math.Max(config.JmdCompression, Deflater.NO_COMPRESSION), Deflater.BEST_COMPRESSION);
ct.CompressionLevel = c;
ct.NumThreads = t;

View File

@ -1,7 +1,7 @@
using System;
using System.IO;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
@ -29,7 +29,7 @@ namespace BizHawk.Client.EmuHawk
{
// ignored
}
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
return new NutWriterToken();
}
@ -137,7 +137,7 @@ namespace BizHawk.Client.EmuHawk
public string DesiredExtension() => "nut";
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
// ignored
}

View File

@ -7,6 +7,7 @@ using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Bizware.BizwareGL;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
@ -21,7 +22,7 @@ namespace BizHawk.Client.EmuHawk
{
}
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
}
@ -82,7 +83,7 @@ namespace BizHawk.Client.EmuHawk
}
}
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
return new DummyDisposable();
}

View File

@ -13,16 +13,16 @@ namespace BizHawk.Client.EmuHawk
public partial class SynclessRecordingTools : Form
{
private readonly List<FrameInfo> _mFrameInfos = new List<FrameInfo>();
private readonly Config _config;
private readonly IGameInfo _game;
private readonly string _avAbsolutePath;
private string _mSynclessConfigFile;
private string _mFramesDirectory;
public SynclessRecordingTools(IGameInfo game, string avAbsolutePath)
public SynclessRecordingTools(Config config, IGameInfo game)
{
_config = config;
_game = game;
_avAbsolutePath = avAbsolutePath;
InitializeComponent();
}
@ -31,7 +31,7 @@ namespace BizHawk.Client.EmuHawk
var ofd = new OpenFileDialog
{
FileName = $"{_game.FilesystemSafeName()}.syncless.txt",
InitialDirectory = _avAbsolutePath
InitialDirectory = _config.PathEntries.AvAbsolutePath()
};
if (ofd.ShowDialog() == DialogResult.Cancel)
@ -123,7 +123,7 @@ namespace BizHawk.Client.EmuHawk
avw.SetAudioParameters(44100, 2, 16); // hacky
avw.SetMovieParameters(60, 1); // hacky
avw.SetVideoParameters(width, height);
var token = avw.AcquireVideoCodecToken(this);
var token = avw.AcquireVideoCodecToken(this, _config);
avw.SetVideoCodecToken(token);
avw.OpenFile(sfd.FileName);
foreach (var fi in _mFrameInfos)

View File

@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common.IOExtensions;
using BizHawk.Emulation.Common;
@ -227,7 +229,7 @@ namespace BizHawk.Client.EmuHawk
public void Dispose() { }
}
public IDisposable AcquireVideoCodecToken(System.Windows.Forms.IWin32Window hwnd)
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd, Config config)
{
// don't care
return new WavWriterVToken();
@ -236,8 +238,8 @@ namespace BizHawk.Client.EmuHawk
/// <exception cref="ArgumentOutOfRangeException"><paramref name="bits"/> is not <c>16</c></exception>
public void SetAudioParameters(int sampleRate, int channels, int bits)
{
this._sampleRate = sampleRate;
this._channels = channels;
_sampleRate = sampleRate;
_channels = channels;
if (bits != 16)
{
throw new ArgumentException("Only support 16bit audio!");
@ -294,7 +296,7 @@ namespace BizHawk.Client.EmuHawk
public string DesiredExtension() => "wav";
public void SetDefaultVideoCodecToken()
public void SetDefaultVideoCodecToken(Config config)
{
// don't use codec tokens, so don't care
}

View File

@ -540,7 +540,7 @@ namespace BizHawk.Client.EmuHawk
private void SynclessRecordingMenuItem_Click(object sender, EventArgs e)
{
new SynclessRecordingTools(Game, Config.PathEntries.AvAbsolutePath()).Run();
new SynclessRecordingTools(Config, Game).Run();
}
private void CaptureOSDMenuItem_Click(object sender, EventArgs e)

View File

@ -3183,7 +3183,7 @@ namespace BizHawk.Client.EmuHawk
// do this before save dialog because ffmpeg won't know what extension it wants until it's been configured
if (unattended && !string.IsNullOrEmpty(filename))
{
aw.SetDefaultVideoCodecToken();
aw.SetDefaultVideoCodecToken(Config);
}
else
{
@ -3191,10 +3191,10 @@ namespace BizHawk.Client.EmuHawk
// PLEASE REDO ME TO NOT CARE WHICH AVWRITER IS USED!
if (usingAvi && !string.IsNullOrEmpty(Config.AviCodecToken))
{
aw.SetDefaultVideoCodecToken();
aw.SetDefaultVideoCodecToken(Config);
}
var token = aw.AcquireVideoCodecToken(this);
var token = aw.AcquireVideoCodecToken(this, Config);
if (token == null)
{
AddOnScreenMessage("A/V capture canceled.");