Skip to content
This repository was archived by the owner on Oct 18, 2025. It is now read-only.

Commit f425c4b

Browse files
funkin.vis
1 parent 6ba0ed5 commit f425c4b

File tree

9 files changed

+294
-188
lines changed

9 files changed

+294
-188
lines changed

Project.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262

6363
<haxelib name="sl-windows-api"/>
6464

65+
<haxelib name="grig.audio"/>
66+
67+
<haxelib name="funkin.vis"/>
68+
6569
<section if="cpp">
6670
<haxelib name="hxdiscord_rpc" if="desktop"/>
6771
<haxelib name="hxvlc" />

setup/install-haxelibs.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ echo Installing dependencies
88
haxelib git hxcpp https://github.com/AlejoGDOfficial/MobilePorting-hxcpp --skip-dependencies
99
haxelib git linc_luajit https://github.com/superpowers04/linc_luajit 633fcc051399afed6781dd60cbf30ed8c3fe2c5a --skip-dependencies
1010
haxelib git SScript https://github.com/AlejoGDOfficial/SScript-7.7.0
11+
haxelib git grig.audio https://gitlab.com/haxe-grig/grig.audio.git cbf91e2180fd2e374924fe74844086aab7891666 --skip-dependencies
12+
haxelib git funkin.vis https://github.com/FunkinCrew/funkVis 1966f8fbbbc509ed90d4b520f3c49c084fc92fd6
1113

1214
haxelib install away3d 5.0.9
1315
haxelib install openfl 9.4.1
16+
haxelib install tink_core 1.26.0
1417
haxelib install tjson 1.4.0
1518
haxelib install sl-windows-api 1.1.0
1619
haxelib install lime 8.2.2
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package funkin.vis.audioclip.frontends;
2+
3+
import flixel.FlxG;
4+
import flixel.math.FlxMath;
5+
import funkin.vis.AudioBuffer;
6+
import lime.media.AudioSource;
7+
8+
/**
9+
* Implementation of AudioClip for Lime.
10+
* On OpenFL you will want SoundChannel.__source (with @:privateAccess)
11+
* For Flixel, you will want to get the FlxSound._channel.__source
12+
*
13+
* Note: On one of the recent OpenFL versions (9.3.2)
14+
* __source was renamed to __audioSource
15+
* https://github.com/openfl/openfl/commit/eec48a
16+
*
17+
*/
18+
class LimeAudioClip implements funkin.vis.AudioClip
19+
{
20+
public var audioBuffer(default, null):AudioBuffer;
21+
public var currentFrame(get, never):Int;
22+
public var source:Dynamic;
23+
24+
public function new(audioSource:AudioSource)
25+
{
26+
var data:lime.utils.UInt16Array = cast audioSource.buffer.data;
27+
28+
#if web
29+
var sampleRate:Float = audioSource.buffer.src._sounds[0]._node.context.sampleRate;
30+
#else
31+
var sampleRate = audioSource.buffer.sampleRate;
32+
#end
33+
34+
this.audioBuffer = new AudioBuffer(data, sampleRate);
35+
this.source = audioSource.buffer.src;
36+
}
37+
38+
private function get_currentFrame():Int
39+
{
40+
var dataLength:Int = 0;
41+
42+
#if web
43+
dataLength = source.length;
44+
#else
45+
dataLength = audioBuffer.data.length;
46+
#end
47+
48+
var value = Std.int(FlxMath.remapToRange(FlxG.sound.music != null ? FlxG.sound.music.time : 0, 0, FlxG.sound.music != null ? FlxG.sound.music.length : 0, 0, FlxG.sound.music != null ? dataLength : 0));
49+
50+
if (value < 0)
51+
return -1;
52+
53+
return value;
54+
}
55+
}

source/funkin/visuals/game/Note.hx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class Note extends FlxSprite
6161

6262
scale.set(0.7, 0.7);
6363

64-
6564
if (noteType == NORMAL)
6665
{
6766
centerOffsets();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package funkin.visuals.objects;
2+
3+
import funkin.vis.dsp.SpectralAnalyzer;
4+
5+
import lime.media.AudioSource;
6+
7+
import flixel.group.FlxGroup;
8+
9+
class Visualizer extends FlxGroup
10+
{
11+
public var bars:FlxTypedGroup<FlxSprite>;
12+
public var analyzer:SpectralAnalyzer;
13+
14+
public final width:Int;
15+
public final height:Int;
16+
17+
public function new(audioSource:AudioSource, ?width:Float, ?height:Float, barCount:Int = 16, color:FlxColor = FlxColor.RED)
18+
{
19+
super();
20+
21+
analyzer = new SpectralAnalyzer(audioSource, barCount, 0.1, 10);
22+
23+
bars = new FlxTypedGroup<FlxSprite>();
24+
add(bars);
25+
26+
this.width = Math.floor(width ?? FlxG.width);
27+
this.height = Math.floor(height ?? FlxG.height);
28+
29+
for (i in 0...barCount)
30+
{
31+
var spr = new FlxSprite((i / barCount) * this.width, 0).makeGraphic(Std.int((1 / barCount) * this.width) - 4, this.height, color);
32+
spr.origin.set(0, this.height);
33+
bars.add(spr);
34+
}
35+
}
36+
37+
@:generic static inline function min<T:Float>(x:T, y:T):T
38+
return x > y ? y : x;
39+
40+
override function draw()
41+
{
42+
@:privateAccess var levels = analyzer.audioSource == null ? [for (i in 0...bars.members.length) {value: 0.0, peak: 0.0}] : analyzer.getLevels();
43+
44+
for (i in 0...min(bars.members.length, levels.length))
45+
bars.members[i].scale.y = levels[i].value;
46+
47+
super.draw();
48+
}
49+
}

source/scripting/haxe/HScript.hx

Lines changed: 3 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,11 @@ import haxe.ds.StringMap;
88
import tea.SScript;
99
import tea.SScript.TeaCall;
1010

11-
import funkin.visuals.cutscenes.DialogueCharacter;
12-
13-
import flixel.input.keyboard.FlxKey;
14-
import flixel.system.macros.FlxMacroUtil;
15-
1611
import core.enums.ScriptType;
1712

18-
import flixel.ui.FlxButton;
13+
import scripting.haxe.HScriptImports;
1914
import flixel.FlxObject;
2015

21-
import ale.ui.ALEButton;
22-
import ale.ui.ALETaskBar;
23-
import ale.ui.ALEUIUtils;
24-
import ale.ui.ALEWindow;
25-
26-
import funkin.visuals.objects.VideoSprite;
27-
28-
import funkin.visuals.editors.chart.ChartNote;
29-
3016
@:access(core.backend.ScriptState)
3117
@:access(core.backend.ScriptSubState)
3218
class HScript extends SScript
@@ -147,8 +133,8 @@ class HScript extends SScript
147133
set(insVar, instanceVariables.get(insVar));
148134

149135
var presetVariables:StringMap<Dynamic> = [
150-
'FlxColor' => FlxColorClass,
151-
'FlxKey' => FlxKeyClass,
136+
'FlxColor' => HScriptFlxColor,
137+
'FlxKey' => HScriptFlxKey,
152138
'Json' => utils.ALEJson,
153139
'debugTrace' => CoolUtil.debugTrace
154140
];
@@ -188,174 +174,4 @@ class HScript extends SScript
188174
return null;
189175
}
190176
}
191-
192-
class FlxColorClass
193-
{
194-
public static var TRANSPARENT(default, null):Int = FlxColor.TRANSPARENT;
195-
public static var BLACK(default, null):Int = FlxColor.BLACK;
196-
public static var WHITE(default, null):Int = FlxColor.WHITE;
197-
public static var GRAY(default, null):Int = FlxColor.GRAY;
198-
199-
public static var GREEN(default, null):Int = FlxColor.GREEN;
200-
public static var LIME(default, null):Int = FlxColor.LIME;
201-
public static var YELLOW(default, null):Int = FlxColor.YELLOW;
202-
public static var ORANGE(default, null):Int = FlxColor.ORANGE;
203-
public static var RED(default, null):Int = FlxColor.RED;
204-
public static var PURPLE(default, null):Int = FlxColor.PURPLE;
205-
public static var BLUE(default, null):Int = FlxColor.BLUE;
206-
public static var BROWN(default, null):Int = FlxColor.BROWN;
207-
public static var PINK(default, null):Int = FlxColor.PINK;
208-
public static var MAGENTA(default, null):Int = FlxColor.MAGENTA;
209-
public static var CYAN(default, null):Int = FlxColor.CYAN;
210-
211-
public static function fromInt(Value:Int):Int
212-
{
213-
return cast FlxColor.fromInt(Value);
214-
}
215-
216-
public static function fromRGB(Red:Int, Green:Int, Blue:Int, Alpha:Int = 255):Int
217-
{
218-
return cast FlxColor.fromRGB(Red, Green, Blue, Alpha);
219-
}
220-
public static function fromRGBFloat(Red:Float, Green:Float, Blue:Float, Alpha:Float = 1):Int
221-
{
222-
return cast FlxColor.fromRGBFloat(Red, Green, Blue, Alpha);
223-
}
224-
225-
public static inline function fromCMYK(Cyan:Float, Magenta:Float, Yellow:Float, Black:Float, Alpha:Float = 1):Int
226-
{
227-
return cast FlxColor.fromCMYK(Cyan, Magenta, Yellow, Black, Alpha);
228-
}
229-
230-
public static function fromHSB(Hue:Float, Sat:Float, Brt:Float, Alpha:Float = 1):Int
231-
{
232-
return cast FlxColor.fromHSB(Hue, Sat, Brt, Alpha);
233-
}
234-
public static function fromHSL(Hue:Float, Sat:Float, Light:Float, Alpha:Float = 1):Int
235-
{
236-
return cast FlxColor.fromHSL(Hue, Sat, Light, Alpha);
237-
}
238-
public static function fromString(str:String):Int
239-
{
240-
return cast FlxColor.fromString(str);
241-
}
242-
}
243-
244-
class FlxKeyClass
245-
{
246-
public static var fromStringMap(default, null):Map<String, FlxKey> = FlxMacroUtil.buildMap("flixel.input.keyboard.FlxKey", false, []);
247-
public static var toStringMap(default, null):Map<FlxKey, String> = FlxMacroUtil.buildMap("flixel.input.keyboard.FlxKey", true, []);
248-
249-
public static var ANY = -2;
250-
public static var NONE = -1;
251-
public static var A = 65;
252-
public static var B = 66;
253-
public static var C = 67;
254-
public static var D = 68;
255-
public static var E = 69;
256-
public static var F = 70;
257-
public static var G = 71;
258-
public static var H = 72;
259-
public static var I = 73;
260-
public static var J = 74;
261-
public static var K = 75;
262-
public static var L = 76;
263-
public static var M = 77;
264-
public static var N = 78;
265-
public static var O = 79;
266-
public static var P = 80;
267-
public static var Q = 81;
268-
public static var R = 82;
269-
public static var S = 83;
270-
public static var T = 84;
271-
public static var U = 85;
272-
public static var V = 86;
273-
public static var W = 87;
274-
public static var X = 88;
275-
public static var Y = 89;
276-
public static var Z = 90;
277-
public static var ZERO = 48;
278-
public static var ONE = 49;
279-
public static var TWO = 50;
280-
public static var THREE = 51;
281-
public static var FOUR = 52;
282-
public static var FIVE = 53;
283-
public static var SIX = 54;
284-
public static var SEVEN = 55;
285-
public static var EIGHT = 56;
286-
public static var NINE = 57;
287-
public static var PAGEUP = 33;
288-
public static var PAGEDOWN = 34;
289-
public static var HOME = 36;
290-
public static var END = 35;
291-
public static var INSERT = 45;
292-
public static var ESCAPE = 27;
293-
public static var MINUS = 189;
294-
public static var PLUS = 187;
295-
public static var DELETE = 46;
296-
public static var BACKSPACE = 8;
297-
public static var LBRACKET = 219;
298-
public static var RBRACKET = 221;
299-
public static var BACKSLASH = 220;
300-
public static var CAPSLOCK = 20;
301-
public static var SCROLL_LOCK = 145;
302-
public static var NUMLOCK = 144;
303-
public static var SEMICOLON = 186;
304-
public static var QUOTE = 222;
305-
public static var ENTER = 13;
306-
public static var SHIFT = 16;
307-
public static var COMMA = 188;
308-
public static var PERIOD = 190;
309-
public static var SLASH = 191;
310-
public static var GRAVEACCENT = 192;
311-
public static var CONTROL = 17;
312-
public static var ALT = 18;
313-
public static var SPACE = 32;
314-
public static var UP = 38;
315-
public static var DOWN = 40;
316-
public static var LEFT = 37;
317-
public static var RIGHT = 39;
318-
public static var TAB = 9;
319-
public static var WINDOWS = 15;
320-
public static var MENU = 302;
321-
public static var PRINTSCREEN = 301;
322-
public static var BREAK = 19;
323-
public static var F1 = 112;
324-
public static var F2 = 113;
325-
public static var F3 = 114;
326-
public static var F4 = 115;
327-
public static var F5 = 116;
328-
public static var F6 = 117;
329-
public static var F7 = 118;
330-
public static var F8 = 119;
331-
public static var F9 = 120;
332-
public static var F10 = 121;
333-
public static var F11 = 122;
334-
public static var F12 = 123;
335-
public static var NUMPADZERO = 96;
336-
public static var NUMPADONE = 97;
337-
public static var NUMPADTWO = 98;
338-
public static var NUMPADTHREE = 99;
339-
public static var NUMPADFOUR = 100;
340-
public static var NUMPADFIVE = 101;
341-
public static var NUMPADSIX = 102;
342-
public static var NUMPADSEVEN = 103;
343-
public static var NUMPADEIGHT = 104;
344-
public static var NUMPADNINE = 105;
345-
public static var NUMPADMINUS = 109;
346-
public static var NUMPADPLUS = 107;
347-
public static var NUMPADPERIOD = 110;
348-
public static var NUMPADMULTIPLY = 106;
349-
public static var NUMPADSLASH = 111;
350-
351-
public static inline function fromString(s:String)
352-
{
353-
s = s.toUpperCase();
354-
355-
return fromStringMap.exists(s) ? fromStringMap.get(s) : NONE;
356-
}
357-
358-
public inline function toString(value:FlxKey):String
359-
return toStringMap.get(value);
360-
}
361177
#end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package scripting.haxe;
2+
3+
class HScriptFlxColor
4+
{
5+
public static var TRANSPARENT(default, null):Int = FlxColor.TRANSPARENT;
6+
public static var BLACK(default, null):Int = FlxColor.BLACK;
7+
public static var WHITE(default, null):Int = FlxColor.WHITE;
8+
public static var GRAY(default, null):Int = FlxColor.GRAY;
9+
10+
public static var GREEN(default, null):Int = FlxColor.GREEN;
11+
public static var LIME(default, null):Int = FlxColor.LIME;
12+
public static var YELLOW(default, null):Int = FlxColor.YELLOW;
13+
public static var ORANGE(default, null):Int = FlxColor.ORANGE;
14+
public static var RED(default, null):Int = FlxColor.RED;
15+
public static var PURPLE(default, null):Int = FlxColor.PURPLE;
16+
public static var BLUE(default, null):Int = FlxColor.BLUE;
17+
public static var BROWN(default, null):Int = FlxColor.BROWN;
18+
public static var PINK(default, null):Int = FlxColor.PINK;
19+
public static var MAGENTA(default, null):Int = FlxColor.MAGENTA;
20+
public static var CYAN(default, null):Int = FlxColor.CYAN;
21+
22+
public static function fromInt(Value:Int):Int
23+
return cast FlxColor.fromInt(Value);
24+
25+
public static function fromRGB(Red:Int, Green:Int, Blue:Int, Alpha:Int = 255):Int
26+
return cast FlxColor.fromRGB(Red, Green, Blue, Alpha);
27+
28+
public static function fromRGBFloat(Red:Float, Green:Float, Blue:Float, Alpha:Float = 1):Int
29+
return cast FlxColor.fromRGBFloat(Red, Green, Blue, Alpha);
30+
31+
public static inline function fromCMYK(Cyan:Float, Magenta:Float, Yellow:Float, Black:Float, Alpha:Float = 1):Int
32+
return cast FlxColor.fromCMYK(Cyan, Magenta, Yellow, Black, Alpha);
33+
34+
public static function fromHSB(Hue:Float, Sat:Float, Brt:Float, Alpha:Float = 1):Int
35+
return cast FlxColor.fromHSB(Hue, Sat, Brt, Alpha);
36+
37+
public static function fromHSL(Hue:Float, Sat:Float, Light:Float, Alpha:Float = 1):Int
38+
return cast FlxColor.fromHSL(Hue, Sat, Light, Alpha);
39+
40+
public static function fromString(str:String):Int
41+
return cast FlxColor.fromString(str);
42+
}

0 commit comments

Comments
 (0)