diff --git a/source/funkin/audio/visualize/PolygonSpectogram.hx b/source/funkin/audio/visualize/PolygonSpectogram.hx index 04eed7f43..7bcebfd25 100644 --- a/source/funkin/audio/visualize/PolygonSpectogram.hx +++ b/source/funkin/audio/visualize/PolygonSpectogram.hx @@ -26,11 +26,11 @@ class PolygonSpectogram extends MeshRender public var thickness:Float = 2; public var waveAmplitude:Int = 100; - public function new(daSound:FlxSound, ?col:FlxColor = FlxColor.WHITE, ?height:Float = 720, ?detail:Float = 1) + public function new(?daSound:FlxSound, ?col:FlxColor = FlxColor.WHITE, ?height:Float = 720, ?detail:Float = 1) { super(0, 0, col); - setSound(daSound); + if (daSound != null) setSound(daSound); if (height != null) this.daHeight = height; diff --git a/source/funkin/audio/visualize/PolygonVisGroup.hx b/source/funkin/audio/visualize/PolygonVisGroup.hx new file mode 100644 index 000000000..03522971c --- /dev/null +++ b/source/funkin/audio/visualize/PolygonVisGroup.hx @@ -0,0 +1,70 @@ +package funkin.audio.visualize; + +import funkin.audio.visualize.PolygonSpectogram; +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.sound.FlxSound; + +class PolygonVisGroup extends FlxTypedGroup +{ + var playerVis:PolygonSpectogram; + var opponentVis:PolygonSpectogram; + var instVis:PolygonSpectogram; + + public function new() + { + super(); + playerVis = new PolygonSpectogram(); + opponentVis = new PolygonSpectogram(); + } + + /** + * Adds the player's visualizer to the group. + * @param visSnd The visualizer to add. + */ + public function addPlayerVis(visSnd:FlxSound):Void + { + var vis:PolygonSpectogram = new PolygonSpectogram(visSnd); + super.add(vis); + playerVis = vis; + } + + /** + * Adds the opponent's visualizer to the group. + * @param visSnd The visualizer to add. + */ + public function addOpponentVis(visSnd:FlxSound):Void + { + var vis:PolygonSpectogram = new PolygonSpectogram(visSnd); + super.add(vis); + opponentVis = vis; + } + + /** + * Adds the instrument's visualizer to the group. + * @param visSnd The visualizer to add. + */ + public function addInstVis(visSnd:FlxSound):Void + { + var vis:PolygonSpectogram = new PolygonSpectogram(visSnd); + super.add(vis); + instVis = vis; + } + + /** + * Overrides the add function to add a visualizer to the group. + * @param vis The visualizer to add. + * @return The added visualizer. + */ + public override function add(vis:PolygonSpectogram):PolygonSpectogram + { + var result:PolygonSpectogram = super.add(vis); + return result; + } + + public override function destroy():Void + { + playerVis.destroy(); + opponentVis.destroy(); + super.destroy(); + } +} diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index 41c67c857..3528801de 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -112,6 +112,7 @@ import haxe.ui.focus.FocusManager; import openfl.display.BitmapData; import funkin.audio.visualize.PolygonSpectogram; import flixel.group.FlxGroup.FlxTypedGroup; +import funkin.audio.visualize.PolygonVisGroup; using Lambda; @@ -902,6 +903,13 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState */ var audioVocalTrackGroup:Null = null; + /** + * The audio vis for the inst/vocals. + * `null` until vocal track(s) are loaded. + * When switching characters, the elements of the PolygonVisGroup will be swapped to match the new character. + */ + var audioVisGroup:Null = null; + /** * A map of the audio tracks for each character's vocals. * - Keys are `characterId-variation` (with `characterId` being the default variation). @@ -1877,8 +1885,8 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState add(healthIconBF); healthIconBF.zIndex = 30; - visulizerGrps = new FlxTypedGroup(); - add(visulizerGrps); + audioVisGroup = new PolygonVisGroup(); + add(audioVisGroup); } function buildNotePreview():Void @@ -5058,10 +5066,6 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState gridPlayheadScrollArea.setGraphicSize(Std.int(gridPlayheadScrollArea.width), songLengthInPixels); gridPlayheadScrollArea.updateHitbox(); } - - var vis:PolygonSpectogram = new PolygonSpectogram(audioInstTrack); - vis.realtimeVisLenght = 1; - visulizerGrps.add(vis); } else { diff --git a/source/funkin/ui/debug/charting/handlers/ChartEditorAudioHandler.hx b/source/funkin/ui/debug/charting/handlers/ChartEditorAudioHandler.hx index f82a123a4..b524de0c8 100644 --- a/source/funkin/ui/debug/charting/handlers/ChartEditorAudioHandler.hx +++ b/source/funkin/ui/debug/charting/handlers/ChartEditorAudioHandler.hx @@ -3,6 +3,7 @@ package funkin.ui.debug.charting.handlers; import flixel.system.FlxAssets.FlxSoundAsset; import flixel.system.FlxSound; import funkin.audio.VoicesGroup; +import funkin.audio.visualize.PolygonVisGroup; import funkin.play.character.BaseCharacter.CharacterType; import funkin.util.FileUtil; import funkin.util.assets.SoundUtil; @@ -168,6 +169,7 @@ class ChartEditorAudioHandler var vocalTrack:Null = SoundUtil.buildFlxSoundFromBytes(vocalTrackData); if (state.audioVocalTrackGroup == null) state.audioVocalTrackGroup = new VoicesGroup(); + if (state.audioVisGroup == null) state.audioVisGroup = new PolygonVisGroup(); if (vocalTrack != null) { @@ -175,6 +177,7 @@ class ChartEditorAudioHandler { case BF: state.audioVocalTrackGroup.addPlayerVoice(vocalTrack); + state.audioVisGroup.addPlayerVis(vocalTrack); return true; case DAD: state.audioVocalTrackGroup.addOpponentVoice(vocalTrack);