Pixel-Composer/scripts/node_audio_window/node_audio_window.gml
2023-10-02 13:57:44 +07:00

44 lines
1.3 KiB
Plaintext

function Node_Audio_Window(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Audio Window";
previewable = false;
w = 96;
h = 32 + 24;
min_h = h;
inputs[| 0] = nodeValue("Audio Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [])
.setArrayDepth(1)
.setVisible(true, true);
inputs[| 1] = nodeValue("Sample", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 44100);
inputs[| 2] = nodeValue("Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 64);
outputs[| 0] = nodeValue("Windowed Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, [])
.setArrayDepth(1);
static update = function(frame = PROJECT.animator.current_frame) {
var _arr = getInputData(0);
if(!is_array(_arr) || array_length(_arr) < 1) return;
if(!is_array(_arr[0])) return;
var sam = getInputData(1);
var siz = getInputData(2);
var res = [];
var off = frame / PROJECT.animator.framerate * sam;
for( var i = 0, n = array_length(_arr); i < n; i++ ) {
var _dat = _arr[i];
res[i] = [];
array_copy(res[i], 0, _dat, off, siz);
}
outputs[| 0].setValue(res);
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_audio_trim, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}