From 32234320a63d4d4cd8ba7cd1b6a17ab83c601276 Mon Sep 17 00:00:00 2001 From: Cam Sinclair Date: Sun, 12 Apr 2020 07:38:39 -0400 Subject: [PATCH] Add OPL to WOPL conversion code to WoplFile --- src/WoplFile.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/WoplFile.cs b/src/WoplFile.cs index e3d660c..588da77 100644 --- a/src/WoplFile.cs +++ b/src/WoplFile.cs @@ -60,5 +60,40 @@ public static WoplFile Serdes(WoplFile w, ISerializer s) public ushort Version { get; set; } = 3; public GlobalBankFlags GlobalFlags { get; set; } public VolumeModel VolumeModel { get; set; } + + public WoplFile() { } + public WoplFile(GlobalTimbreLibrary timbreLibrary) + { + Version = 3; + GlobalFlags = GlobalBankFlags.DeepTremolo | GlobalBankFlags.DeepVibrato; + VolumeModel = VolumeModel.Auto; + + Melodic.Add(new WoplBank { Id = 0, Name = "" }); + Percussion.Add(new WoplBank { Id = 0, Name = "" }); + + for(int i = 0; i < timbreLibrary.Data.Count; i++) + { + var timbre = timbreLibrary.Data[i]; + WoplInstrument x = + i < 128 + ? Melodic[0].Instruments[i] ?? new WoplInstrument() + : Percussion[0].Instruments[i - 128 + 35] ?? new WoplInstrument(); + + x.Name = ""; + x.NoteOffset1 = timbre.MidiPatchNumber; + x.NoteOffset2 = timbre.MidiBankNumber; + x.InstrumentMode = InstrumentMode.TwoOperator; + x.FbConn1C0 = timbre.FeedbackConnection; + x.Operator0 = timbre.Carrier; + x.Operator1 = timbre.Modulation; + x.Operator2 = Operator.Blank; + x.Operator3 = Operator.Blank; + + if (i < 128) + Melodic[0].Instruments[i] = x; + else + Percussion[0].Instruments[i - 128 + 35] = x; + } + } } }