2023-05-25 22:34:26 +00:00
|
|
|
package funkin.audio;
|
|
|
|
|
2023-12-06 20:04:24 +00:00
|
|
|
import funkin.audio.FunkinSound;
|
2023-05-25 22:34:26 +00:00
|
|
|
import flixel.group.FlxGroup.FlxTypedGroup;
|
2024-01-26 01:23:18 +00:00
|
|
|
import funkin.audio.waveform.WaveformData;
|
|
|
|
import funkin.audio.waveform.WaveformDataParser;
|
2023-05-25 22:34:26 +00:00
|
|
|
|
|
|
|
class VoicesGroup extends SoundGroup
|
|
|
|
{
|
2023-12-06 20:04:24 +00:00
|
|
|
var playerVoices:FlxTypedGroup<FunkinSound>;
|
|
|
|
var opponentVoices:FlxTypedGroup<FunkinSound>;
|
2023-05-25 22:34:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Control the volume of only the sounds in the player group.
|
|
|
|
*/
|
2023-12-05 07:44:57 +00:00
|
|
|
public var playerVolume(default, set):Float = 1.0;
|
2023-05-25 22:34:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Control the volume of only the sounds in the opponent group.
|
|
|
|
*/
|
2023-12-05 07:44:57 +00:00
|
|
|
public var opponentVolume(default, set):Float = 1.0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time offset for the player's vocal track.
|
|
|
|
*/
|
|
|
|
public var playerVoicesOffset(default, set):Float = 0.0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time offset for the opponent's vocal track.
|
|
|
|
*/
|
|
|
|
public var opponentVoicesOffset(default, set):Float = 0.0;
|
2023-05-25 22:34:26 +00:00
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
2023-12-06 20:04:24 +00:00
|
|
|
playerVoices = new FlxTypedGroup<FunkinSound>();
|
|
|
|
opponentVoices = new FlxTypedGroup<FunkinSound>();
|
2023-05-25 22:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a voice to the player group.
|
|
|
|
*/
|
2023-12-06 20:04:24 +00:00
|
|
|
public function addPlayerVoice(sound:FunkinSound):Void
|
2023-05-25 22:34:26 +00:00
|
|
|
{
|
|
|
|
super.add(sound);
|
|
|
|
playerVoices.add(sound);
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_playerVolume(volume:Float):Float
|
|
|
|
{
|
2023-12-06 20:04:24 +00:00
|
|
|
playerVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-05-25 22:34:26 +00:00
|
|
|
voice.volume = volume;
|
|
|
|
});
|
|
|
|
return playerVolume = volume;
|
|
|
|
}
|
|
|
|
|
2023-12-05 07:44:57 +00:00
|
|
|
override function set_time(time:Float):Float
|
|
|
|
{
|
|
|
|
forEachAlive(function(snd) {
|
|
|
|
// account for different offsets per sound?
|
|
|
|
snd.time = time;
|
|
|
|
});
|
|
|
|
|
2023-12-06 20:04:24 +00:00
|
|
|
playerVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-12-05 07:44:57 +00:00
|
|
|
voice.time -= playerVoicesOffset;
|
|
|
|
});
|
2023-12-06 20:04:24 +00:00
|
|
|
opponentVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-12-05 07:44:57 +00:00
|
|
|
voice.time -= opponentVoicesOffset;
|
|
|
|
});
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_playerVoicesOffset(offset:Float):Float
|
|
|
|
{
|
2023-12-06 20:04:24 +00:00
|
|
|
playerVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-12-05 07:44:57 +00:00
|
|
|
voice.time += playerVoicesOffset;
|
|
|
|
voice.time -= offset;
|
|
|
|
});
|
|
|
|
return playerVoicesOffset = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_opponentVoicesOffset(offset:Float):Float
|
|
|
|
{
|
2023-12-06 20:04:24 +00:00
|
|
|
opponentVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-12-05 07:44:57 +00:00
|
|
|
voice.time += opponentVoicesOffset;
|
|
|
|
voice.time -= offset;
|
|
|
|
});
|
|
|
|
return opponentVoicesOffset = offset;
|
|
|
|
}
|
|
|
|
|
2023-05-25 22:34:26 +00:00
|
|
|
/**
|
|
|
|
* Add a voice to the opponent group.
|
|
|
|
*/
|
2023-12-06 20:04:24 +00:00
|
|
|
public function addOpponentVoice(sound:FunkinSound):Void
|
2023-05-25 22:34:26 +00:00
|
|
|
{
|
|
|
|
super.add(sound);
|
|
|
|
opponentVoices.add(sound);
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_opponentVolume(volume:Float):Float
|
|
|
|
{
|
2023-12-06 20:04:24 +00:00
|
|
|
opponentVoices.forEachAlive(function(voice:FunkinSound) {
|
2023-05-25 22:34:26 +00:00
|
|
|
voice.volume = volume;
|
|
|
|
});
|
|
|
|
return opponentVolume = volume;
|
|
|
|
}
|
|
|
|
|
2024-01-27 08:24:49 +00:00
|
|
|
public function getPlayerVoice(index:Int = 0):Null<FunkinSound>
|
|
|
|
{
|
|
|
|
return playerVoices.members[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOpponentVoice(index:Int = 0):Null<FunkinSound>
|
|
|
|
{
|
|
|
|
return opponentVoices.members[index];
|
|
|
|
}
|
|
|
|
|
2024-02-09 19:58:57 +00:00
|
|
|
public function getPlayerVoiceWaveform():Null<WaveformData>
|
2024-01-26 01:23:18 +00:00
|
|
|
{
|
|
|
|
if (playerVoices.members.length == 0) return null;
|
|
|
|
|
2024-02-09 19:58:57 +00:00
|
|
|
return playerVoices.members[0].waveformData;
|
2024-01-26 01:23:18 +00:00
|
|
|
}
|
|
|
|
|
2024-02-09 19:58:57 +00:00
|
|
|
public function getOpponentVoiceWaveform():Null<WaveformData>
|
2024-01-26 01:23:18 +00:00
|
|
|
{
|
|
|
|
if (opponentVoices.members.length == 0) return null;
|
|
|
|
|
2024-02-09 19:58:57 +00:00
|
|
|
return opponentVoices.members[0].waveformData;
|
2024-01-26 01:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The length of the player's vocal track, in milliseconds.
|
|
|
|
*/
|
|
|
|
public function getPlayerVoiceLength():Float
|
|
|
|
{
|
|
|
|
if (playerVoices.members.length == 0) return 0.0;
|
|
|
|
|
|
|
|
return playerVoices.members[0].length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The length of the opponent's vocal track, in milliseconds.
|
|
|
|
*/
|
|
|
|
public function getOpponentVoiceLength():Float
|
|
|
|
{
|
|
|
|
if (opponentVoices.members.length == 0) return 0.0;
|
|
|
|
|
|
|
|
return opponentVoices.members[0].length;
|
|
|
|
}
|
|
|
|
|
2023-05-25 22:34:26 +00:00
|
|
|
public override function clear():Void
|
|
|
|
{
|
|
|
|
playerVoices.clear();
|
|
|
|
opponentVoices.clear();
|
|
|
|
super.clear();
|
|
|
|
}
|
2023-07-14 00:27:45 +00:00
|
|
|
|
|
|
|
public override function destroy():Void
|
|
|
|
{
|
2024-03-29 01:40:16 +00:00
|
|
|
if (playerVoices != null)
|
|
|
|
{
|
|
|
|
playerVoices.destroy();
|
|
|
|
playerVoices = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opponentVoices != null)
|
|
|
|
{
|
|
|
|
opponentVoices.destroy();
|
|
|
|
opponentVoices = null;
|
|
|
|
}
|
|
|
|
|
2023-07-14 00:27:45 +00:00
|
|
|
super.destroy();
|
|
|
|
}
|
2023-05-25 22:34:26 +00:00
|
|
|
}
|