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:
co-authored by
Claude Opus 4.7
parent
7f227acb6a
commit
dd805a4cd9
@@ -50,11 +50,8 @@ Plays through a playlist one song at a time, blending three intensity layers per
|
||||
| `Playlist` | `DynamicSoundPlaylist` | `null` | Songs to play in order. Mutated as songs finish. |
|
||||
| `Intensity` | `float` (0–1) | `0` | Runtime mix between the three layers. `0` = layer 1 dominates, `1` = layer 3 dominates. |
|
||||
| `Loop` | `bool` | `false` | When true, finished songs are re-queued at the back so the playlist cycles forever. |
|
||||
| `PitchMode` | enum | `Constant` | `Constant` or `Random` (placeholder — pitch logic not yet implemented). |
|
||||
| `RandomMinPitchScale` | `float` | `-0.5` | Minimum pitch when `PitchMode = Random`. Hidden in the inspector when `PitchMode = Constant`. |
|
||||
| `RandomMaxPitchScale` | `float` | `0.5` | Maximum pitch when `PitchMode = Random`. Hidden in the inspector when `PitchMode = Constant`. |
|
||||
|
||||
The `stream` property is auto-assigned an `AudioStreamPolyphonic` when the node enters the tree in the editor, so you don't need to configure it manually.
|
||||
When the node enters the tree in the editor, `stream` is auto-assigned an `AudioStreamPolyphonic` and `bus` is set to `"Music"` if a bus by that name exists in the project (otherwise it's left at `"Master"`). User-customised buses are not overridden.
|
||||
|
||||
#### Methods
|
||||
|
||||
@@ -83,12 +80,19 @@ Each `play_fx()` call fires a fresh trigger of the assigned `DynamicSound`. Trig
|
||||
| --- | --- | --- | --- |
|
||||
| `Sound` | `DynamicSound` | `null` | The sound to trigger. Layers with intensity blending if all three are set. |
|
||||
| `Intensity` | `float` (0–1) | `0` | Volume mix between layers. Only blended when all three layers are present; otherwise the first non-null layer plays at full volume. |
|
||||
| `PitchMode` | enum | `Constant` | `Constant` plays each trigger at pitch `1.0`. `Random` picks a fresh pitch per trigger via `1.0 + randf_range(RandomMinPitchScale, RandomMaxPitchScale)`. |
|
||||
| `RandomMinPitchScale` | `float` | `-0.5` | Minimum pitch offset (added to `1.0`) when `PitchMode = Random`. Hidden in the inspector when `PitchMode = Constant`. |
|
||||
| `RandomMaxPitchScale` | `float` | `0.5` | Maximum pitch offset (added to `1.0`) when `PitchMode = Random`. Hidden in the inspector when `PitchMode = Constant`. |
|
||||
|
||||
When the node enters the tree in the editor, `stream` is auto-assigned an `AudioStreamPolyphonic` and `bus` is set to `"FX"` if a bus by that name exists in the project (otherwise it's left at `"Master"`). User-customised buses are not overridden.
|
||||
|
||||
For a *constant non-1.0* pitch, set the player's built-in `pitch_scale` property — that multiplies with whatever `PitchMode` produces, so e.g. `pitch_scale = 0.8` + `PitchMode = Random` with default range gives an effective pitch in `[0.4, 1.2]`.
|
||||
|
||||
#### Methods
|
||||
|
||||
| Method | Description |
|
||||
| --- | --- |
|
||||
| `play_fx()` | Triggers a fresh play of `Sound`. Volumes are computed at trigger time and locked in — later changes to `Intensity` or `volume_db` don't affect already-playing triggers. |
|
||||
| `play_fx()` | Triggers a fresh play of `Sound`. Pitch is sampled at trigger time per `PitchMode`. Volumes are computed at trigger time and locked in — later changes to `Intensity` or `volume_db` don't affect already-playing triggers. |
|
||||
|
||||
#### Example: collision SFX
|
||||
|
||||
|
||||
Reference in New Issue
Block a user