2024-01-20 19:07:48 +00:00
|
|
|
package funkin.ui.debug;
|
|
|
|
|
2024-01-24 19:35:50 +00:00
|
|
|
import flixel.math.FlxRect;
|
2024-01-20 19:07:48 +00:00
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.util.FlxColor;
|
|
|
|
import funkin.audio.FunkinSound;
|
|
|
|
import funkin.audio.waveform.WaveformData;
|
2024-01-24 03:47:27 +00:00
|
|
|
import funkin.audio.waveform.WaveformSprite;
|
2024-01-20 19:07:48 +00:00
|
|
|
import funkin.audio.waveform.WaveformDataParser;
|
|
|
|
import funkin.graphics.rendering.MeshRender;
|
|
|
|
|
|
|
|
class WaveformTestState extends MusicBeatState
|
|
|
|
{
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
var waveformData:WaveformData;
|
2024-01-24 03:47:27 +00:00
|
|
|
var waveformData2:WaveformData;
|
2024-01-20 19:07:48 +00:00
|
|
|
|
|
|
|
var waveformAudio:FunkinSound;
|
|
|
|
|
2024-01-24 03:47:27 +00:00
|
|
|
var waveformSprite:WaveformSprite;
|
2024-01-20 19:07:48 +00:00
|
|
|
|
2024-01-24 03:47:27 +00:00
|
|
|
// var waveformSprite2:WaveformSprite;
|
2024-01-20 19:07:48 +00:00
|
|
|
var timeMarker:FlxSprite;
|
|
|
|
|
|
|
|
public override function create():Void
|
|
|
|
{
|
|
|
|
super.create();
|
|
|
|
|
2024-01-24 19:35:50 +00:00
|
|
|
var testSprite = new FlxSprite(0, 0);
|
|
|
|
testSprite.loadGraphic(Paths.image('funkay'));
|
|
|
|
testSprite.updateHitbox();
|
2024-01-26 00:10:33 +00:00
|
|
|
testSprite.clipRect = new FlxRect(0, 0, FlxG.width, FlxG.height);
|
2024-01-24 19:35:50 +00:00
|
|
|
add(testSprite);
|
|
|
|
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformAudio = FunkinSound.load(Paths.inst('bopeebo', '-erect'));
|
2024-01-20 19:07:48 +00:00
|
|
|
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformData = WaveformDataParser.interpretFlxSound(waveformAudio);
|
2024-01-20 19:07:48 +00:00
|
|
|
|
2024-01-26 00:10:33 +00:00
|
|
|
waveformSprite = WaveformSprite.buildFromWaveformData(waveformData, HORIZONTAL, FlxColor.fromString("#ADD8E6"));
|
|
|
|
waveformSprite.duration = 5.0 * 160;
|
|
|
|
waveformSprite.width = FlxG.width * 160;
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformSprite.height = FlxG.height; // / 2;
|
2024-01-26 00:10:33 +00:00
|
|
|
waveformSprite.amplitude = 2.0;
|
|
|
|
waveformSprite.minWaveformSize = 25;
|
|
|
|
waveformSprite.clipRect = new FlxRect(0, 0, FlxG.width, FlxG.height);
|
2024-01-24 03:47:27 +00:00
|
|
|
add(waveformSprite);
|
|
|
|
|
|
|
|
// waveformSprite2 = WaveformSprite.buildFromWaveformData(waveformData2, HORIZONTAL, FlxColor.fromString("#FF0000"), 5.0);
|
|
|
|
// waveformSprite2.width = FlxG.width;
|
|
|
|
// waveformSprite2.height = FlxG.height / 2;
|
|
|
|
// waveformSprite2.y = FlxG.height / 2;
|
|
|
|
// add(waveformSprite2);
|
2024-01-20 19:07:48 +00:00
|
|
|
|
|
|
|
timeMarker = new FlxSprite(0, FlxG.height * 1 / 6);
|
|
|
|
timeMarker.makeGraphic(1, Std.int(FlxG.height * 2 / 3), FlxColor.RED);
|
|
|
|
add(timeMarker);
|
|
|
|
|
2024-01-24 03:47:27 +00:00
|
|
|
// drawWaveform(time, duration);
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 03:47:27 +00:00
|
|
|
public override function update(elapsed:Float):Void
|
2024-01-20 19:07:48 +00:00
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
super.update(elapsed);
|
2024-01-20 19:07:48 +00:00
|
|
|
|
2024-01-24 03:47:27 +00:00
|
|
|
if (FlxG.keys.justPressed.SPACE)
|
2024-01-20 19:07:48 +00:00
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
if (waveformAudio.isPlaying)
|
2024-01-20 19:07:48 +00:00
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformAudio.stop();
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
2024-01-24 03:47:27 +00:00
|
|
|
else
|
2024-01-20 19:07:48 +00:00
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformAudio.play();
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-24 03:47:27 +00:00
|
|
|
if (FlxG.keys.justPressed.ENTER)
|
2024-01-20 19:07:48 +00:00
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
if (waveformSprite.orientation == HORIZONTAL)
|
2024-01-20 19:07:48 +00:00
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformSprite.orientation = VERTICAL;
|
|
|
|
// waveformSprite2.orientation = VERTICAL;
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformSprite.orientation = HORIZONTAL;
|
|
|
|
// waveformSprite2.orientation = HORIZONTAL;
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (waveformAudio.isPlaying)
|
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
// waveformSprite takes a time in fractional seconds, not milliseconds.
|
|
|
|
var timeSeconds = waveformAudio.time / 1000;
|
|
|
|
waveformSprite.time = timeSeconds;
|
|
|
|
// waveformSprite2.time = timeSeconds;
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.UP)
|
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformSprite.duration += 1.0;
|
|
|
|
// waveformSprite2.duration += 1.0;
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
if (FlxG.keys.justPressed.DOWN)
|
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformSprite.duration -= 1.0;
|
|
|
|
// waveformSprite2.duration -= 1.0;
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
if (FlxG.keys.justPressed.LEFT)
|
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformSprite.time -= 1.0;
|
|
|
|
// waveformSprite2.time -= 1.0;
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
if (FlxG.keys.justPressed.RIGHT)
|
|
|
|
{
|
2024-01-24 03:47:27 +00:00
|
|
|
waveformSprite.time += 1.0;
|
|
|
|
// waveformSprite2.time += 1.0;
|
2024-01-20 19:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function destroy():Void
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
}
|