NSF: Fixed UI crash when switching between different NSF files

This commit is contained in:
Sour 2019-12-29 10:39:14 -05:00
parent ad986023e0
commit 42a7404d4f
3 changed files with 38 additions and 19 deletions

View file

@ -72,7 +72,6 @@
this.tlpRepeatShuffle = new System.Windows.Forms.TableLayoutPanel();
this.picRepeat = new System.Windows.Forms.PictureBox();
this.picShuffle = new System.Windows.Forms.PictureBox();
this.tmrUpdate = new System.Windows.Forms.Timer(this.components);
this.tlpMain.SuspendLayout();
this.tlpNsfInfo.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout();
@ -671,12 +670,6 @@
this.picShuffle.TabStop = false;
this.picShuffle.Click += new System.EventHandler(this.picShuffle_Click);
//
// tmrUpdate
//
this.tmrUpdate.Enabled = false;
this.tmrUpdate.Interval = 250;
this.tmrUpdate.Tick += new System.EventHandler(this.tmrUpdate_Tick);
//
// ctrlNsfPlayer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -759,7 +752,6 @@
private System.Windows.Forms.PictureBox picShuffle;
private System.Windows.Forms.PictureBox picRepeat;
private System.Windows.Forms.Panel pnlBackground;
private System.Windows.Forms.Timer tmrUpdate;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Label lblRewinding;
private System.Windows.Forms.Label lblRewindIcon;

View file

@ -14,12 +14,14 @@ namespace Mesen.GUI.Controls
{
public partial class ctrlNsfPlayer : BaseControl
{
private InteropEmu.NotificationListener _notifListener;
private List<ComboboxItem> _trackList = new List<ComboboxItem>();
private bool _fastForwarding = false;
private UInt32 _originalSpeed = 100;
private bool _disableShortcutKeys = false;
private float _xFactor = 1;
private float _yFactor = 1;
private bool _isNsf = false;
public ctrlNsfPlayer()
{
@ -27,12 +29,40 @@ namespace Mesen.GUI.Controls
ThemeHelper.ExcludeFromTheme(this);
}
private void notifListener_OnNotification(InteropEmu.NotificationEventArgs e)
{
switch(e.NotificationType) {
case InteropEmu.ConsoleNotificationType.GameLoaded:
_isNsf = InteropEmu.IsNsf();
break;
case InteropEmu.ConsoleNotificationType.PpuFrameDone:
if(_isNsf) {
UInt32 elapsedFrames = InteropEmu.NsfGetFrameCount();
if((elapsedFrames % 15) == 0) {
this.BeginInvoke((Action)(() => this.UpdateTimeDisplay()));
}
}
break;
}
}
protected override void OnHandleDestroyed(EventArgs e)
{
base.OnHandleDestroyed(e);
_notifListener?.Dispose();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if(!IsDesignMode) {
this.tmrUpdate.Enabled = true;
_isNsf = InteropEmu.IsNsf();
_notifListener = new InteropEmu.NotificationListener(InteropEmu.ConsoleId.Master);
_notifListener.OnNotification += notifListener_OnNotification;
this.btnNext.KeyUp += Child_KeyUp;
this.btnPause.KeyUp += Child_KeyUp;
this.btnPrevious.KeyUp += Child_KeyUp;
@ -122,7 +152,7 @@ namespace Mesen.GUI.Controls
private void UpdateTimeDisplay()
{
if(!InteropEmu.IsNsf()) {
if(!_isNsf) {
return;
}
@ -182,6 +212,10 @@ namespace Mesen.GUI.Controls
private void UpdateTrackDisplay()
{
if(!_isNsf) {
return;
}
NsfHeader header = InteropEmu.NsfGetHeader();
int currentTrack = InteropEmu.NsfGetCurrentTrack();
@ -212,7 +246,8 @@ namespace Mesen.GUI.Controls
if(this.InvokeRequired) {
this.BeginInvoke((MethodInvoker)(() => UpdateText()));
} else {
if(InteropEmu.IsNsf()) {
_isNsf = InteropEmu.IsNsf();
if(_isNsf) {
UpdateTrackDisplay();
UpdateTimeDisplay();
@ -439,11 +474,6 @@ namespace Mesen.GUI.Controls
this.tlpNsfInfo.MouseMove -= value;
}
}
private void tmrUpdate_Tick(object sender, EventArgs e)
{
UpdateTimeDisplay();
}
}
public class ComboboxItem

View file

@ -123,7 +123,4 @@
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>154, 17</value>
</metadata>
<metadata name="tmrUpdate.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>244, 17</value>
</metadata>
</root>