From 466181bbbdfc5e139a7709412c5f1912f15e342f Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 20 Sep 2021 11:32:35 -0400 Subject: [PATCH] sound grouping in progress --- source/ChartingState.hx | 11 +++---- source/Paths.hx | 7 +++-- source/SpectogramSprite.hx | 2 +- source/VoicesGroup.hx | 61 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 source/VoicesGroup.hx diff --git a/source/ChartingState.hx b/source/ChartingState.hx index 2bd7565eb..15831dc40 100644 --- a/source/ChartingState.hx +++ b/source/ChartingState.hx @@ -82,7 +82,7 @@ class ChartingState extends MusicBeatState var tempBpm:Float = 0; - var vocals:FlxSound; + var vocals:VoicesGroup; var leftIcon:HealthIcon; var rightIcon:HealthIcon; @@ -404,17 +404,18 @@ class ChartingState extends MusicBeatState add(playheadTest); // WONT WORK FOR TUTORIAL OR TEST SONG!!! REDO LATER - vocals = new FlxSound().loadEmbedded(Paths.voices(daSong)); - FlxG.sound.list.add(vocals); + vocals = new VoicesGroup(daSong); + // vocals = new FlxSound().loadEmbedded(Paths.voices(daSong)); + // FlxG.sound.list.add(vocals); - var vocalSpec:SpectogramSprite = new SpectogramSprite(vocals); + var vocalSpec:SpectogramSprite = new SpectogramSprite(vocals.members[0]); vocalSpec.x += 70; vocalSpec.daHeight = musSpec.daHeight; vocalSpec.y = vocalSpec.daHeight; vocalSpec.scrollFactor.set(); add(vocalSpec); - spec = new SpectogramSprite(vocals); + spec = new SpectogramSprite(vocals.members[0]); spec.x -= 150; spec.daHeight = GRID_SIZE * 16; spec.visType = STATIC; diff --git a/source/Paths.hx b/source/Paths.hx index aa8c17fd5..e1b42b901 100644 --- a/source/Paths.hx +++ b/source/Paths.hx @@ -84,9 +84,12 @@ class Paths return getPath('music/$key.$SOUND_EXT', MUSIC, library); } - inline static public function voices(song:String) + inline static public function voices(song:String, ?suffix:String) { - return 'songs:assets/songs/${song.toLowerCase()}/Voices.$SOUND_EXT'; + if (suffix == null) + suffix = ""; // no suffix, for a sorta backwards compatibility with older-ish voice files + + return 'songs:assets/songs/${song.toLowerCase()}/Voices$suffix.$SOUND_EXT'; } inline static public function inst(song:String) diff --git a/source/SpectogramSprite.hx b/source/SpectogramSprite.hx index a2e8481ea..54848b920 100644 --- a/source/SpectogramSprite.hx +++ b/source/SpectogramSprite.hx @@ -103,7 +103,7 @@ class SpectogramSprite extends FlxTypedSpriteGroup public function checkAndSetBuffer() { - if (daSound.playing) + if (daSound != null && daSound.playing) { if (!setBuffer) { diff --git a/source/VoicesGroup.hx b/source/VoicesGroup.hx new file mode 100644 index 000000000..94e1ad9e0 --- /dev/null +++ b/source/VoicesGroup.hx @@ -0,0 +1,61 @@ +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.system.FlxSound; + +// different than FlxSoundGroup cuz this can control all the sounds time and shit +// when needed +class VoicesGroup extends FlxTypedGroup +{ + public var time(default, set):Float = 0; + + // make it a group that you add to? + public function new(song:String, ?files:Array) + { + super(); + + if (files == null) + files = [""]; // loads with no file name assumption, to load "Voices.ogg" or whatev normally + + for (sndFile in files) + { + var snd:FlxSound = new FlxSound().loadEmbedded(Paths.voices(song, '$sndFile')); + FlxG.sound.list.add(snd); // adds it to sound group for proper volumes + add(snd); // adds it to main group for other shit + } + } + + // prob a better / cleaner way to do all these forEach stuff? + public function pause() + { + forEachAlive(function(snd) + { + snd.pause(); + }); + } + + public function play() + { + forEachAlive(function(snd) + { + snd.play(); + }); + } + + public function stop() + { + forEachAlive(function(snd) + { + snd.stop(); + }); + } + + function set_time(time:Float):Float + { + forEachAlive(function(snd) + { + // account for different offsets per sound? + snd.time = time; + }); + + return time; + } +}