Skip to content

Commit 09ff66d

Browse files
committed
- 6.4.2.0 Added DMC Envelope property to the RP2A03 Fx.
1 parent 631ec96 commit 09ff66d

File tree

3 files changed

+162
-7
lines changed

3 files changed

+162
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MAmidiMEmo 6.4.1.0 Itoken (c)2019, 2025 / GPL-2.0
1+
MAmidiMEmo 6.4.2.0 Itoken (c)2019, 2025 / GPL-2.0
22

33
*** What is the MAmidiMEmo? ***
44

@@ -278,6 +278,7 @@ e.g.) YM2151 has 8ch FM sounds, so you can play 8 chords on MIDI 1ch or sharing
278278
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SNQ9JE3JAQMNQ)
279279

280280
*** Changes
281+
- 6.4.2.0 Added DMC Envelope property to the RP2A03 Fx.
281282
- 6.4.1.0 Check if there is a difference in sample rate between the DAW and MAmi.
282283
- 6.4.0.0 Added VST3 version VST plugin.
283284
- 6.3.1.0 When selecting a file in Timbre Manager, you can test play the first sound in the list.

src/mamidimemo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static class Program
4141
/// <summary>
4242
///
4343
/// </summary>
44-
public const string FILE_VERSION = "6.4.1.0";
44+
public const string FILE_VERSION = "6.4.2.0";
4545

4646
public const string FILE_COPYRIGHT = @"Virtual chiptune sound MIDI module ""MAmidiMEmo"" Version {0}
4747
Copyright(C) 2019, 2025 Itoken.All rights reserved.";

src/mamidimemo/instruments/Chips/RP2A03.cs

Lines changed: 159 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,8 +2054,15 @@ private void updateSqVolume()
20542054
/// </summary>
20552055
private void updateTriVolume()
20562056
{
2057-
if (IsSoundOff)
2058-
return;
2057+
if (FxEngine != null && FxEngine.Active)
2058+
{
2059+
var eng = (NesFxEngine)FxEngine;
2060+
if (eng.DmcValue != null)
2061+
{
2062+
byte dmcVal = (byte)(eng.DmcValue.Value & 3);
2063+
parentModule.RP2A03WriteData(parentModule.UnitNumber, 0x11, dmcVal, false, false);
2064+
}
2065+
}
20592066

20602067
var fv = Math.Round(timbre.Volume * CalcCurrentVolume());
20612068

@@ -2079,6 +2086,16 @@ private void updateTriVolume()
20792086
/// </summary>
20802087
private void updateNoiseVolume()
20812088
{
2089+
if (FxEngine != null && FxEngine.Active)
2090+
{
2091+
var eng = (NesFxEngine)FxEngine;
2092+
if (eng.DmcValue != null)
2093+
{
2094+
byte dmcVal = (byte)(eng.DmcValue.Value & 3);
2095+
parentModule.RP2A03WriteData(parentModule.UnitNumber, 0x11, dmcVal, false, false);
2096+
}
2097+
}
2098+
20822099
byte fv = (byte)((byte)Math.Round(timbre.Volume * CalcCurrentVolume()) & 0xf);
20832100

20842101
byte dd = timbre.DecayDisable;
@@ -2092,9 +2109,8 @@ private void updateNoiseVolume()
20922109
/// </summary>
20932110
private void updateDpcmVolume()
20942111
{
2095-
var vol = parentModule.Volumes[NoteOnEvent.Channel];
2096-
2097-
parentModule.RP2A03WriteData(parentModule.UnitNumber, (uint)(0x11), vol);
2112+
//var vol = parentModule.Volumes[NoteOnEvent.Channel];
2113+
//parentModule.RP2A03WriteData(parentModule.UnitNumber, (uint)(0x11), vol);
20982114
}
20992115

21002116

@@ -3379,6 +3395,100 @@ public void ResetDutyEnvelopes()
33793395
public int DutyEnvelopesReleasePoint { get; set; } = -1;
33803396

33813397

3398+
private string f_DmcEnvelopes;
3399+
3400+
[DataMember]
3401+
[Description("Set DMC envelop by text. Input DMC value and split it with space like the FamiTracker.\r\n" +
3402+
"0-127 \"|\" is repeat point. \"/\" is release point.")]
3403+
[Editor(typeof(EnvelopeUITypeEditor), typeof(System.Drawing.Design.UITypeEditor))]
3404+
[EnvelopeEditorAttribute(0, 127)]
3405+
public string DmcEnvelopes
3406+
{
3407+
get
3408+
{
3409+
return f_DmcEnvelopes;
3410+
}
3411+
set
3412+
{
3413+
if (f_DmcEnvelopes != value)
3414+
{
3415+
DmcEnvelopesRepeatPoint = -1;
3416+
DmcEnvelopesReleasePoint = -1;
3417+
if (value == null)
3418+
{
3419+
DmcEnvelopesNums = new int[] { };
3420+
f_DmcEnvelopes = string.Empty;
3421+
return;
3422+
}
3423+
f_DmcEnvelopes = value;
3424+
string[] vals = value.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
3425+
List<int> vs = new List<int>();
3426+
for (int i = 0; i < vals.Length; i++)
3427+
{
3428+
string val = vals[i];
3429+
if (val.Equals("|", StringComparison.Ordinal))
3430+
DmcEnvelopesRepeatPoint = vs.Count;
3431+
else if (val.Equals("/", StringComparison.Ordinal))
3432+
DmcEnvelopesReleasePoint = vs.Count;
3433+
else
3434+
{
3435+
int v;
3436+
if (int.TryParse(val, out v))
3437+
{
3438+
if (v < 0)
3439+
v = 0;
3440+
else if (v > 127)
3441+
v = 127;
3442+
vs.Add(v);
3443+
}
3444+
}
3445+
}
3446+
DmcEnvelopesNums = vs.ToArray();
3447+
3448+
StringBuilder sb = new StringBuilder();
3449+
for (int i = 0; i < DmcEnvelopesNums.Length; i++)
3450+
{
3451+
if (sb.Length != 0)
3452+
sb.Append(' ');
3453+
if (DmcEnvelopesRepeatPoint == i)
3454+
sb.Append("| ");
3455+
if (DmcEnvelopesReleasePoint == i)
3456+
sb.Append("/ ");
3457+
if (i < DmcEnvelopesNums.Length)
3458+
sb.Append(DmcEnvelopesNums[i].ToString((IFormatProvider)null));
3459+
}
3460+
f_DmcEnvelopes = sb.ToString();
3461+
}
3462+
}
3463+
}
3464+
3465+
public bool ShouldSerializeDmcEnvelopes()
3466+
{
3467+
return !string.IsNullOrEmpty(DmcEnvelopes);
3468+
}
3469+
3470+
public void ResetDmcEnvelopes()
3471+
{
3472+
DmcEnvelopes = null;
3473+
}
3474+
3475+
[Browsable(false)]
3476+
[JsonIgnore]
3477+
[IgnoreDataMember]
3478+
public int[] DmcEnvelopesNums { get; set; } = new int[] { };
3479+
3480+
[Browsable(false)]
3481+
[JsonIgnore]
3482+
[IgnoreDataMember]
3483+
[DefaultValue(-1)]
3484+
public int DmcEnvelopesRepeatPoint { get; set; } = -1;
3485+
3486+
[Browsable(false)]
3487+
[JsonIgnore]
3488+
[IgnoreDataMember]
3489+
[DefaultValue(-1)]
3490+
public int DmcEnvelopesReleasePoint { get; set; } = -1;
3491+
33823492
private string f_MorphEnvelopes;
33833493

33843494
[DataMember]
@@ -3884,6 +3994,15 @@ public byte? DutyValue
38843994
}
38853995

38863996

3997+
private uint f_dmcCounter;
3998+
3999+
public byte? DmcValue
4000+
{
4001+
get;
4002+
private set;
4003+
}
4004+
4005+
38874006
private uint f_morphCounter;
38884007

38894008
public byte? MorphValue
@@ -3964,6 +4083,41 @@ protected override bool ProcessCore(SoundBase sound, bool isKeyOff, bool isSound
39644083
}
39654084
}
39664085

4086+
DmcValue = null;
4087+
if (settings.DmcEnvelopesNums.Length > 0)
4088+
{
4089+
if (!isKeyOff)
4090+
{
4091+
var vm = settings.DmcEnvelopesNums.Length;
4092+
if (settings.DmcEnvelopesReleasePoint >= 0)
4093+
vm = settings.DmcEnvelopesReleasePoint;
4094+
if (f_dmcCounter >= vm)
4095+
{
4096+
if (settings.DmcEnvelopesRepeatPoint >= 0)
4097+
f_dmcCounter = (uint)settings.DmcEnvelopesRepeatPoint;
4098+
else
4099+
f_dmcCounter = (uint)vm;
4100+
}
4101+
}
4102+
else
4103+
{
4104+
if (f_dmcCounter < settings.DmcEnvelopesNums.Length)
4105+
{
4106+
if (settings.DmcEnvelopesReleasePoint >= 0 && f_dmcCounter <= (uint)settings.DmcEnvelopesReleasePoint)
4107+
f_dmcCounter = (uint)settings.DmcEnvelopesReleasePoint;
4108+
else if (settings.DmcEnvelopesReleasePoint < 0 && settings.KeyOffStop)
4109+
f_dmcCounter = (uint)settings.DmcEnvelopesNums.Length;
4110+
}
4111+
}
4112+
if (f_dmcCounter < settings.DmcEnvelopesNums.Length)
4113+
{
4114+
int vol = settings.DmcEnvelopesNums[f_dmcCounter++];
4115+
4116+
DmcValue = (byte)vol;
4117+
process = true;
4118+
}
4119+
}
4120+
39674121

39684122
MorphValue = null;
39694123
if (settings.MorphEnvelopesNums.Length > 0)

0 commit comments

Comments
 (0)