From 6ebf3f577ec4d3b49a7797ef586ec6926a51a6c8 Mon Sep 17 00:00:00 2001 From: 110-kenichi <110.kenichi@gmail.com> Date: Sat, 7 Nov 2020 14:56:51 +0900 Subject: [PATCH] Improved MIDI file Player UI. Fixed MML Serializer can not deserialize "," separator. --- .../Gui/FMEditor/RegisterContainerBase.cs | 7 ++++++- src/mamidimemo/Gui/FormMain.Designer.cs | 17 +++++++++-------- src/mamidimemo/Gui/FormMain.cs | 10 ++++++++-- src/mamidimemo/instruments/Chips/YM2612.cs | 3 ++- src/mamidimemo/instruments/SimpleSerializer.cs | 9 +++++++-- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/mamidimemo/Gui/FMEditor/RegisterContainerBase.cs b/src/mamidimemo/Gui/FMEditor/RegisterContainerBase.cs index 924dea56a8b04..2cabce83a7167 100644 --- a/src/mamidimemo/Gui/FMEditor/RegisterContainerBase.cs +++ b/src/mamidimemo/Gui/FMEditor/RegisterContainerBase.cs @@ -11,6 +11,7 @@ using zanac.MAmidiMEmo.Instruments; using zanac.MAmidiMEmo.ComponentModel; using System.Reflection; +using System.Collections; namespace zanac.MAmidiMEmo.Gui.FMEditor { @@ -206,7 +207,11 @@ public static void DeserializeProps(T obj, string serializeData, params strin try { serializeData = serializeData.Replace("\r", "").Replace("\n", ""); - var vals = serializeData.Split(new char[] { ',', ' ', '\t' }).GetEnumerator(); + IEnumerator vals = null; + if (serializeData.Contains(',')) + vals = serializeData.Split(new char[] { ',' }).GetEnumerator(); + else + vals = serializeData.Split(new char[] { ' ', '\t' }).GetEnumerator(); foreach (string m in props) { if (!vals.MoveNext()) diff --git a/src/mamidimemo/Gui/FormMain.Designer.cs b/src/mamidimemo/Gui/FormMain.Designer.cs index 771caa18dee24..e4f5c7394339d 100644 --- a/src/mamidimemo/Gui/FormMain.Designer.cs +++ b/src/mamidimemo/Gui/FormMain.Designer.cs @@ -98,6 +98,7 @@ private void InitializeComponent() this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.labelCpuLoad = new System.Windows.Forms.Label(); + this.panelChDisp = new System.Windows.Forms.Panel(); this.toolStrip4 = new zanac.MAmidiMEmo.Gui.ClickThroughToolStrip(); this.toolStripButtonPlay = new System.Windows.Forms.ToolStripButton(); this.toolStripButtonPause = new System.Windows.Forms.ToolStripButton(); @@ -162,7 +163,6 @@ private void InitializeComponent() this.fileSystemWatcherMidi = new System.IO.FileSystemWatcher(); this.timerReload = new System.Windows.Forms.Timer(this.components); this.saveFileDialogMAmidi = new System.Windows.Forms.SaveFileDialog(); - this.panelChDisp = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -1027,6 +1027,14 @@ private void InitializeComponent() this.labelCpuLoad.Name = "labelCpuLoad"; this.labelCpuLoad.UseCompatibleTextRendering = true; // + // panelChDisp + // + this.panelChDisp.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(126)))), ((int)(((byte)(0))))); + resources.ApplyResources(this.panelChDisp, "panelChDisp"); + this.panelChDisp.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(115)))), ((int)(((byte)(63)))), ((int)(((byte)(0))))); + this.panelChDisp.Name = "panelChDisp"; + this.panelChDisp.Paint += new System.Windows.Forms.PaintEventHandler(this.panelChDisp_Paint); + // // toolStrip4 // this.toolStrip4.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -1483,13 +1491,6 @@ private void InitializeComponent() resources.ApplyResources(this.saveFileDialogMAmidi, "saveFileDialogMAmidi"); this.saveFileDialogMAmidi.SupportMultiDottedExtensions = true; // - // panelChDisp - // - this.panelChDisp.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(126)))), ((int)(((byte)(0))))); - resources.ApplyResources(this.panelChDisp, "panelChDisp"); - this.panelChDisp.Name = "panelChDisp"; - this.panelChDisp.Paint += new System.Windows.Forms.PaintEventHandler(this.panelChDisp_Paint); - // // FormMain // resources.ApplyResources(this, "$this"); diff --git a/src/mamidimemo/Gui/FormMain.cs b/src/mamidimemo/Gui/FormMain.cs index 9e0f0f876c788..a65cfd6a04927 100644 --- a/src/mamidimemo/Gui/FormMain.cs +++ b/src/mamidimemo/Gui/FormMain.cs @@ -1407,12 +1407,18 @@ private void MidiManager_MidiEventReceived(object sender, MidiEvent e) { if (e.EventType == MidiEventType.NoteOn) { - NoteOnEvent noe = (NoteOnEvent)e; - if (noe.Velocity != 0) + NoteOnEvent noe = e as NoteOnEvent; + if (noe != null && noe.Velocity != 0) { lock (chNoteOnData) chNoteOnData[noe.Channel] = noe.Velocity; } + TaggedNoteOnEvent tnoe = e as TaggedNoteOnEvent; + if (tnoe != null && tnoe.Velocity != 0) + { + lock (chNoteOnData) + chNoteOnData[tnoe.Channel] = tnoe.Velocity; + } } } diff --git a/src/mamidimemo/instruments/Chips/YM2612.cs b/src/mamidimemo/instruments/Chips/YM2612.cs index 2a86da25b31d9..a35c450461632 100644 --- a/src/mamidimemo/instruments/Chips/YM2612.cs +++ b/src/mamidimemo/instruments/Chips/YM2612.cs @@ -1242,7 +1242,8 @@ public string MmlSerializeData set { SimpleSerializer.DeserializeProps(this, value, - nameof(ALG), + + nameof(ALG), nameof(FB), "Ops[0].AR", diff --git a/src/mamidimemo/instruments/SimpleSerializer.cs b/src/mamidimemo/instruments/SimpleSerializer.cs index 6d16e6c5dea1e..0f8bb2abce08c 100644 --- a/src/mamidimemo/instruments/SimpleSerializer.cs +++ b/src/mamidimemo/instruments/SimpleSerializer.cs @@ -1,5 +1,6 @@ // copyright-holders:K.Ito using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -29,7 +30,7 @@ public static string SerializeProps(T obj, params string[] props) sb.Append(","); var f = getPropertyInfo(obj, m); var val = f.Property.GetValue(f.Owner); - if(val != null) + if (val != null) sb.Append(val.ToString()); } } @@ -58,7 +59,11 @@ public static void DeserializeProps(T obj, string serializeData, params strin try { serializeData = serializeData.Replace("\r", "").Replace("\n", ""); - var vals = serializeData.Split(new char[] { ',', ' ', '\t' }).GetEnumerator(); + IEnumerator vals = null; + if (serializeData.Contains(',')) + vals = serializeData.Split(new char[] { ',' }).GetEnumerator(); + else + vals = serializeData.Split(new char[] { ' ', '\t' }).GetEnumerator(); foreach (string m in props) { if (!vals.MoveNext())