2022-03-08 03:13:53 -05:00
|
|
|
package funkin;
|
|
|
|
|
2021-09-20 11:32:35 -04:00
|
|
|
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<FlxSound>
|
|
|
|
{
|
|
|
|
public var time(default, set):Float = 0;
|
|
|
|
|
2021-09-20 11:50:52 -04:00
|
|
|
public var volume(default, set):Float = 1;
|
|
|
|
|
2021-12-30 00:09:16 -05:00
|
|
|
public var pitch(default, set):Float = 1;
|
|
|
|
|
2021-09-20 11:32:35 -04:00
|
|
|
// make it a group that you add to?
|
2021-09-20 11:50:52 -04:00
|
|
|
public function new(song:String, ?files:Array<String>, ?needsVoices:Bool = true)
|
2021-09-20 11:32:35 -04:00
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2021-09-20 11:50:52 -04:00
|
|
|
if (!needsVoices)
|
|
|
|
{
|
|
|
|
// simply adds an empty sound? fills it in moreso for easier backwards compatibility
|
|
|
|
add(new FlxSound());
|
|
|
|
// FlxG.sound.list.add(snd);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-20 11:32:35 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-09 19:07:39 -05:00
|
|
|
/**
|
|
|
|
* Finds the largest deviation from the desired time inside this VoicesGroup.
|
|
|
|
*
|
|
|
|
* @param targetTime The time to check against.
|
|
|
|
* If none is provided, it checks the time of all members against the first member of this VoicesGroup.
|
|
|
|
* @return The largest deviation from the target time found.
|
|
|
|
*/
|
|
|
|
public function checkSyncError(?targetTime:Float):Float
|
|
|
|
{
|
|
|
|
var error:Float = 0;
|
|
|
|
|
|
|
|
forEachAlive(function(snd)
|
|
|
|
{
|
|
|
|
if (targetTime == null)
|
|
|
|
targetTime = snd.time;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var diff:Float = snd.time - targetTime;
|
|
|
|
if (Math.abs(diff) > Math.abs(error))
|
|
|
|
error = diff;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2021-09-20 11:32:35 -04:00
|
|
|
// 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;
|
|
|
|
}
|
2021-09-20 11:50:52 -04:00
|
|
|
|
|
|
|
// in PlayState, adjust the code so that it only mutes the player1 vocal tracks?
|
|
|
|
function set_volume(volume:Float):Float
|
|
|
|
{
|
|
|
|
forEachAlive(function(snd)
|
|
|
|
{
|
|
|
|
snd.volume = volume;
|
|
|
|
});
|
|
|
|
|
|
|
|
return volume;
|
|
|
|
}
|
2021-12-30 00:09:16 -05:00
|
|
|
|
|
|
|
function set_pitch(val:Float):Float
|
|
|
|
{
|
|
|
|
#if HAS_PITCH
|
|
|
|
forEachAlive(function(snd)
|
|
|
|
{
|
|
|
|
snd.pitch = val;
|
|
|
|
});
|
|
|
|
#end
|
|
|
|
return val;
|
|
|
|
}
|
2021-09-20 11:32:35 -04:00
|
|
|
}
|