Minimum MIDI note volume (#6127)

This commit is contained in:
Hannah Giovanna Dawson
2025-08-05 22:35:48 +01:00
committed by GitHub
parent 8cbc5d4cd8
commit 1fb7d3e723
2 changed files with 11 additions and 1 deletions

View File

@@ -213,4 +213,6 @@ public interface IMidiRenderer : IDisposable
/// Actually disposes of this renderer. Do NOT use outside the MIDI thread.
/// </summary>
internal void InternalDispose();
byte MinVolume { get; set; }
}

View File

@@ -214,6 +214,11 @@ internal sealed partial class MidiRenderer : IMidiRenderer
[ViewVariables]
public BitArray FilteredChannels { get; } = new(RobustMidiEvent.MaxChannels);
[ViewVariables]
public byte MinVolume { get => _minVolume; set => _minVolume = value; }
private byte _minVolume;
[ViewVariables(VVAccess.ReadWrite)]
public byte? VelocityOverride { get; set; } = null;
@@ -591,7 +596,10 @@ internal sealed partial class MidiRenderer : IMidiRenderer
if (FilteredChannels[midiEvent.Channel])
break;
velocity = VelocityOverride ?? midiEvent.Velocity;
if (MinVolume > 0)
velocity = (byte)Math.Floor(MathHelper.Lerp(MinVolume, 127, (float)velocity / 127));
velocity = VelocityOverride ?? velocity;
_rendererState.NoteVelocities.AsSpan[midiEvent.Channel].AsSpan[midiEvent.Key] = velocity;
_synth.NoteOn(midiEvent.Channel, midiEvent.Key, velocity);