move PitchMode to FX players and implement random pitch

The continuous music players had PitchMode/RandomMin/MaxPitchScale exports but
no logic referenced them. Pitch variation only makes sense per-trigger, which
the FX family supports natively. So:

- Remove PitchMode, RandomMinPitchScale, RandomMaxPitchScale, and the
  _validate_property hook from DynamicSoundPlayer / 2D / 3D.
- Add the same exports + _validate_property to DynamicSoundFXPlayer / 2D / 3D.
- Implement pitch resolution in DynamicSoundFXPlayerCore.play_fx: each trigger
  samples a fresh pitch from PitchMode and passes it as the pitch_scale
  argument to AudioStreamPlaybackPolyphonic.play_stream.
- Random pitch uses 1.0 + randf_range(min, max) so the existing -0.5/0.5
  defaults give a useful [0.5, 1.5] pitch range.
- README updated to reflect the move.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Samson
2026-04-29 15:03:03 +01:00
co-authored by Claude Opus 4.7
parent 7f227acb6a
commit dd805a4cd9
8 changed files with 67 additions and 56 deletions
+16
View File
@@ -14,6 +14,17 @@ extends AudioStreamPlayer2D
## Volume mix between intensity layers. Only blended when all three layers are set.
@export_range(0, 1) var Intensity : float = 0;
## How playback pitch is selected for each [method play_fx] trigger.
@export var PitchMode : DynamicSoundConstants.PitchMode = DynamicSoundConstants.PitchMode.Constant:
set(value):
PitchMode = value;
notify_property_list_changed();
## Minimum pitch offset (added to 1.0) when [member PitchMode] is Random.
@export var RandomMinPitchScale : float = -0.5;
## Maximum pitch offset (added to 1.0) when [member PitchMode] is Random.
@export var RandomMaxPitchScale : float = 0.5;
var _core : DynamicSoundFXPlayerCore;
func _enter_tree() -> void:
@@ -24,6 +35,11 @@ func _enter_tree() -> void:
if bus == &"Master" and AudioServer.get_bus_index("FX") != -1:
bus = "FX";
func _validate_property(property: Dictionary) -> void:
if property.name in ["RandomMinPitchScale", "RandomMaxPitchScale"]:
if PitchMode != DynamicSoundConstants.PitchMode.Random:
property.usage &= ~PROPERTY_USAGE_EDITOR;
func _ready() -> void:
_core = DynamicSoundFXPlayerCore.new(self);
_core.ready();