mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +00:00
chore: format codes
This commit is contained in:
@@ -47,7 +47,7 @@ function Editor(container_id, options) {
|
||||
".tools-right"
|
||||
);
|
||||
|
||||
if (!options.skip_livemode)
|
||||
if (!options.skip_livemode) {
|
||||
this.addToolsButton(
|
||||
"livemode_button",
|
||||
"Live",
|
||||
@@ -55,7 +55,8 @@ function Editor(container_id, options) {
|
||||
this.onLiveButton.bind(this),
|
||||
".tools-right"
|
||||
);
|
||||
if (!options.skip_maximize)
|
||||
}
|
||||
if (!options.skip_maximize) {
|
||||
this.addToolsButton(
|
||||
"maximize_button",
|
||||
"",
|
||||
@@ -63,11 +64,16 @@ function Editor(container_id, options) {
|
||||
this.onFullscreenButton.bind(this),
|
||||
".tools-right"
|
||||
);
|
||||
if (options.miniwindow) this.addMiniWindow(300, 200);
|
||||
}
|
||||
if (options.miniwindow) {
|
||||
this.addMiniWindow(300, 200);
|
||||
}
|
||||
|
||||
//append to DOM
|
||||
var parent = document.getElementById(container_id);
|
||||
if (parent) parent.appendChild(root);
|
||||
if (parent) {
|
||||
parent.appendChild(root);
|
||||
}
|
||||
|
||||
graphcanvas.resize();
|
||||
//graphcanvas.draw(true,true);
|
||||
@@ -89,10 +95,12 @@ Editor.prototype.addLoadCounter = function() {
|
||||
setInterval(function() {
|
||||
meter.querySelector(".cpuload .fgload").style.width =
|
||||
2 * self.graph.execution_time * 90 + "px";
|
||||
if (self.graph.status == LGraph.STATUS_RUNNING)
|
||||
if (self.graph.status == LGraph.STATUS_RUNNING) {
|
||||
meter.querySelector(".gpuload .fgload").style.width =
|
||||
self.graphcanvas.render_time * 10 * 90 + "px";
|
||||
else meter.querySelector(".gpuload .fgload").style.width = 4 + "px";
|
||||
} else {
|
||||
meter.querySelector(".gpuload .fgload").style.width = 4 + "px";
|
||||
}
|
||||
}, 200);
|
||||
};
|
||||
|
||||
@@ -103,7 +111,9 @@ Editor.prototype.addToolsButton = function(
|
||||
callback,
|
||||
container
|
||||
) {
|
||||
if (!container) container = ".tools";
|
||||
if (!container) {
|
||||
container = ".tools";
|
||||
}
|
||||
|
||||
var button = this.createButton(name, icon_url);
|
||||
button.id = id;
|
||||
@@ -128,7 +138,9 @@ Editor.prototype.createPanel = function(title, options) {
|
||||
|
||||
Editor.prototype.createButton = function(name, icon_url) {
|
||||
var button = document.createElement("button");
|
||||
if (icon_url) button.innerHTML = "<img src='" + icon_url + "'/> ";
|
||||
if (icon_url) {
|
||||
button.innerHTML = "<img src='" + icon_url + "'/> ";
|
||||
}
|
||||
button.innerHTML += name;
|
||||
return button;
|
||||
};
|
||||
@@ -181,13 +193,15 @@ Editor.prototype.onLiveButton = function() {
|
||||
};
|
||||
|
||||
Editor.prototype.goFullscreen = function() {
|
||||
if (this.root.requestFullscreen)
|
||||
if (this.root.requestFullscreen) {
|
||||
this.root.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||
else if (this.root.mozRequestFullscreen)
|
||||
} else if (this.root.mozRequestFullscreen) {
|
||||
this.root.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||
else if (this.root.webkitRequestFullscreen)
|
||||
} else if (this.root.webkitRequestFullscreen) {
|
||||
this.root.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||
else throw "Fullscreen not supported";
|
||||
} else {
|
||||
throw "Fullscreen not supported";
|
||||
}
|
||||
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
|
||||
3102
src/litegraph.js
3102
src/litegraph.js
File diff suppressed because it is too large
Load Diff
@@ -51,24 +51,32 @@
|
||||
for (var i = 0; i < node.inputs.length; ++i) {
|
||||
var input = node.inputs[i];
|
||||
var link_info = node.graph.links[input.link];
|
||||
if (!link_info) continue;
|
||||
if (!link_info) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var origin_node = node.graph.getNodeById(link_info.origin_id);
|
||||
var origin_audionode = null;
|
||||
if (origin_node.getAudioNodeInOutputSlot)
|
||||
if (origin_node.getAudioNodeInOutputSlot) {
|
||||
origin_audionode = origin_node.getAudioNodeInOutputSlot(
|
||||
link_info.origin_slot
|
||||
);
|
||||
else origin_audionode = origin_node.audionode;
|
||||
} else {
|
||||
origin_audionode = origin_node.audionode;
|
||||
}
|
||||
|
||||
var target_audionode = null;
|
||||
if (node.getAudioNodeInInputSlot)
|
||||
if (node.getAudioNodeInInputSlot) {
|
||||
target_audionode = node.getAudioNodeInInputSlot(i);
|
||||
else target_audionode = node.audionode;
|
||||
} else {
|
||||
target_audionode = node.audionode;
|
||||
}
|
||||
|
||||
if (connect)
|
||||
if (connect) {
|
||||
LGAudio.connect(origin_audionode, target_audionode);
|
||||
else LGAudio.disconnect(origin_audionode, target_audionode);
|
||||
} else {
|
||||
LGAudio.disconnect(origin_audionode, target_audionode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,26 +85,34 @@
|
||||
var output = node.outputs[i];
|
||||
for (var j = 0; j < output.links.length; ++j) {
|
||||
var link_info = node.graph.links[output.links[j]];
|
||||
if (!link_info) continue;
|
||||
if (!link_info) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var origin_audionode = null;
|
||||
if (node.getAudioNodeInOutputSlot)
|
||||
if (node.getAudioNodeInOutputSlot) {
|
||||
origin_audionode = node.getAudioNodeInOutputSlot(i);
|
||||
else origin_audionode = node.audionode;
|
||||
} else {
|
||||
origin_audionode = node.audionode;
|
||||
}
|
||||
|
||||
var target_node = node.graph.getNodeById(
|
||||
link_info.target_id
|
||||
);
|
||||
var target_audionode = null;
|
||||
if (target_node.getAudioNodeInInputSlot)
|
||||
if (target_node.getAudioNodeInInputSlot) {
|
||||
target_audionode = target_node.getAudioNodeInInputSlot(
|
||||
link_info.target_slot
|
||||
);
|
||||
else target_audionode = target_node.audionode;
|
||||
} else {
|
||||
target_audionode = target_node.audionode;
|
||||
}
|
||||
|
||||
if (connect)
|
||||
if (connect) {
|
||||
LGAudio.connect(origin_audionode, target_audionode);
|
||||
else LGAudio.disconnect(origin_audionode, target_audionode);
|
||||
} else {
|
||||
LGAudio.disconnect(origin_audionode, target_audionode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,31 +126,43 @@
|
||||
link_info
|
||||
) {
|
||||
//only process the outputs events
|
||||
if (connection != LiteGraph.OUTPUT) return;
|
||||
if (connection != LiteGraph.OUTPUT) {
|
||||
return;
|
||||
}
|
||||
|
||||
var target_node = null;
|
||||
if (link_info)
|
||||
if (link_info) {
|
||||
target_node = this.graph.getNodeById(link_info.target_id);
|
||||
}
|
||||
|
||||
if (!target_node) return;
|
||||
if (!target_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
//get origin audionode
|
||||
var local_audionode = null;
|
||||
if (this.getAudioNodeInOutputSlot)
|
||||
if (this.getAudioNodeInOutputSlot) {
|
||||
local_audionode = this.getAudioNodeInOutputSlot(slot);
|
||||
else local_audionode = this.audionode;
|
||||
} else {
|
||||
local_audionode = this.audionode;
|
||||
}
|
||||
|
||||
//get target audionode
|
||||
var target_audionode = null;
|
||||
if (target_node.getAudioNodeInInputSlot)
|
||||
if (target_node.getAudioNodeInInputSlot) {
|
||||
target_audionode = target_node.getAudioNodeInInputSlot(
|
||||
link_info.target_slot
|
||||
);
|
||||
else target_audionode = target_node.audionode;
|
||||
} else {
|
||||
target_audionode = target_node.audionode;
|
||||
}
|
||||
|
||||
//do the connection/disconnection
|
||||
if (connected) LGAudio.connect(local_audionode, target_audionode);
|
||||
else LGAudio.disconnect(local_audionode, target_audionode);
|
||||
if (connected) {
|
||||
LGAudio.connect(local_audionode, target_audionode);
|
||||
} else {
|
||||
LGAudio.disconnect(local_audionode, target_audionode);
|
||||
}
|
||||
};
|
||||
|
||||
//this function helps creating wrappers to existing classes
|
||||
@@ -142,15 +170,23 @@
|
||||
var old_func = class_object.prototype.onPropertyChanged;
|
||||
|
||||
class_object.prototype.onPropertyChanged = function(name, value) {
|
||||
if (old_func) old_func.call(this, name, value);
|
||||
if (old_func) {
|
||||
old_func.call(this, name, value);
|
||||
}
|
||||
|
||||
if (!this.audionode) return;
|
||||
if (!this.audionode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.audionode[name] === undefined) return;
|
||||
if (this.audionode[name] === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.audionode[name].value !== undefined)
|
||||
if (this.audionode[name].value !== undefined) {
|
||||
this.audionode[name].value = value;
|
||||
else this.audionode[name] = value;
|
||||
} else {
|
||||
this.audionode[name] = value;
|
||||
}
|
||||
};
|
||||
|
||||
class_object.prototype.onConnectionsChange =
|
||||
@@ -162,11 +198,15 @@
|
||||
|
||||
LGAudio.loadSound = function(url, on_complete, on_error) {
|
||||
if (LGAudio.cached_audios[url] && url.indexOf("blob:") == -1) {
|
||||
if (on_complete) on_complete(LGAudio.cached_audios[url]);
|
||||
if (on_complete) {
|
||||
on_complete(LGAudio.cached_audios[url]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (LGAudio.onProcessAudioURL) url = LGAudio.onProcessAudioURL(url);
|
||||
if (LGAudio.onProcessAudioURL) {
|
||||
url = LGAudio.onProcessAudioURL(url);
|
||||
}
|
||||
|
||||
//load new sample
|
||||
var request = new XMLHttpRequest();
|
||||
@@ -183,7 +223,9 @@
|
||||
function(buffer) {
|
||||
console.log("AudioSource decoded");
|
||||
LGAudio.cached_audios[url] = buffer;
|
||||
if (on_complete) on_complete(buffer);
|
||||
if (on_complete) {
|
||||
on_complete(buffer);
|
||||
}
|
||||
},
|
||||
onError
|
||||
);
|
||||
@@ -192,7 +234,9 @@
|
||||
|
||||
function onError(err) {
|
||||
console.log("Audio loading sample error:", err);
|
||||
if (on_error) on_error(err);
|
||||
if (on_error) {
|
||||
on_error(err);
|
||||
}
|
||||
}
|
||||
|
||||
return request;
|
||||
@@ -226,20 +270,28 @@
|
||||
this.audionode.gain.value = this.properties.gain;
|
||||
|
||||
//debug
|
||||
if (this.properties.src) this.loadSound(this.properties.src);
|
||||
if (this.properties.src) {
|
||||
this.loadSound(this.properties.src);
|
||||
}
|
||||
}
|
||||
|
||||
LGAudioSource["@src"] = { widget: "resource" };
|
||||
LGAudioSource.supported_extensions = ["wav", "ogg", "mp3"];
|
||||
|
||||
LGAudioSource.prototype.onAdded = function(graph) {
|
||||
if (graph.status === LGraph.STATUS_RUNNING) this.onStart();
|
||||
if (graph.status === LGraph.STATUS_RUNNING) {
|
||||
this.onStart();
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioSource.prototype.onStart = function() {
|
||||
if (!this._audiobuffer) return;
|
||||
if (!this._audiobuffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.properties.autoplay) this.playBuffer(this._audiobuffer);
|
||||
if (this.properties.autoplay) {
|
||||
this.playBuffer(this._audiobuffer);
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioSource.prototype.onStop = function() {
|
||||
@@ -257,7 +309,9 @@
|
||||
|
||||
LGAudioSource.prototype.onRemoved = function() {
|
||||
this.stopAllSounds();
|
||||
if (this._dropped_url) URL.revokeObjectURL(this._url);
|
||||
if (this._dropped_url) {
|
||||
URL.revokeObjectURL(this._url);
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioSource.prototype.stopAllSounds = function() {
|
||||
@@ -281,41 +335,56 @@
|
||||
};
|
||||
|
||||
LGAudioSource.prototype.onExecute = function() {
|
||||
if (this.inputs)
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
if (input.link == null) continue;
|
||||
if (input.link == null) {
|
||||
continue;
|
||||
}
|
||||
var v = this.getInputData(i);
|
||||
if (v === undefined) continue;
|
||||
if (input.name == "gain") this.audionode.gain.value = v;
|
||||
else if (input.name == "playbackRate") {
|
||||
if (v === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (input.name == "gain") {
|
||||
this.audionode.gain.value = v;
|
||||
} else if (input.name == "playbackRate") {
|
||||
this.properties.playbackRate = v;
|
||||
for (var j = 0; j < this._audionodes.length; ++j)
|
||||
for (var j = 0; j < this._audionodes.length; ++j) {
|
||||
this._audionodes[j].playbackRate.value = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.outputs)
|
||||
if (this.outputs) {
|
||||
for (var i = 0; i < this.outputs.length; ++i) {
|
||||
var output = this.outputs[i];
|
||||
if (output.name == "buffer" && this._audiobuffer)
|
||||
if (output.name == "buffer" && this._audiobuffer) {
|
||||
this.setOutputData(i, this._audiobuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioSource.prototype.onAction = function(event) {
|
||||
if (this._audiobuffer) {
|
||||
if (event == "Play") this.playBuffer(this._audiobuffer);
|
||||
else if (event == "Stop") this.stopAllSounds();
|
||||
if (event == "Play") {
|
||||
this.playBuffer(this._audiobuffer);
|
||||
} else if (event == "Stop") {
|
||||
this.stopAllSounds();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioSource.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "src") this.loadSound(value);
|
||||
else if (name == "gain") this.audionode.gain.value = value;
|
||||
else if (name == "playbackRate") {
|
||||
for (var j = 0; j < this._audionodes.length; ++j)
|
||||
if (name == "src") {
|
||||
this.loadSound(value);
|
||||
} else if (name == "gain") {
|
||||
this.audionode.gain.value = value;
|
||||
} else if (name == "playbackRate") {
|
||||
for (var j = 0; j < this._audionodes.length; ++j) {
|
||||
this._audionodes[j].playbackRate.value = value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -339,7 +408,9 @@
|
||||
that.trigger("ended");
|
||||
//remove
|
||||
var index = that._audionodes.indexOf(audionode);
|
||||
if (index != -1) that._audionodes.splice(index, 1);
|
||||
if (index != -1) {
|
||||
that._audionodes.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
if (!audionode.started) {
|
||||
@@ -361,7 +432,9 @@
|
||||
this._audiobuffer = null; //points to the audiobuffer once the audio is loaded
|
||||
this._loading_audio = false;
|
||||
|
||||
if (!url) return;
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._request = LGAudio.loadSound(url, inner);
|
||||
|
||||
@@ -373,8 +446,9 @@
|
||||
that._audiobuffer = buffer;
|
||||
that._loading_audio = false;
|
||||
//if is playing, then play it
|
||||
if (that.graph && that.graph.status === LGraph.STATUS_RUNNING)
|
||||
that.onStart(); //this controls the autoplay already
|
||||
if (that.graph && that.graph.status === LGraph.STATUS_RUNNING) {
|
||||
that.onStart();
|
||||
} //this controls the autoplay already
|
||||
}
|
||||
};
|
||||
|
||||
@@ -394,7 +468,9 @@
|
||||
};
|
||||
|
||||
LGAudioSource.prototype.onDropFile = function(file) {
|
||||
if (this._dropped_url) URL.revokeObjectURL(this._dropped_url);
|
||||
if (this._dropped_url) {
|
||||
URL.revokeObjectURL(this._dropped_url);
|
||||
}
|
||||
var url = URL.createObjectURL(file);
|
||||
this.properties.src = url;
|
||||
this.loadSound(url);
|
||||
@@ -426,12 +502,15 @@
|
||||
}
|
||||
|
||||
LGAudioMediaSource.prototype.onAdded = function(graph) {
|
||||
if (graph.status === LGraph.STATUS_RUNNING) this.onStart();
|
||||
if (graph.status === LGraph.STATUS_RUNNING) {
|
||||
this.onStart();
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioMediaSource.prototype.onStart = function() {
|
||||
if (this._media_stream == null && !this._waiting_confirmation)
|
||||
if (this._media_stream == null && !this._waiting_confirmation) {
|
||||
this.openStream();
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioMediaSource.prototype.onStop = function() {
|
||||
@@ -454,7 +533,9 @@
|
||||
}
|
||||
if (this._media_stream) {
|
||||
var tracks = this._media_stream.getTracks();
|
||||
if (tracks.length) tracks[0].stop();
|
||||
if (tracks.length) {
|
||||
tracks[0].stop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -487,8 +568,9 @@
|
||||
//this._waiting_confirmation = false;
|
||||
|
||||
//init context
|
||||
if (this.audiosource_node)
|
||||
if (this.audiosource_node) {
|
||||
this.audiosource_node.disconnect(this.audionode);
|
||||
}
|
||||
var context = LGAudio.getAudioContext();
|
||||
this.audiosource_node = context.createMediaStreamSource(
|
||||
localMediaStream
|
||||
@@ -499,27 +581,39 @@
|
||||
};
|
||||
|
||||
LGAudioMediaSource.prototype.onExecute = function() {
|
||||
if (this._media_stream == null && !this._waiting_confirmation)
|
||||
if (this._media_stream == null && !this._waiting_confirmation) {
|
||||
this.openStream();
|
||||
}
|
||||
|
||||
if (this.inputs)
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
if (input.link == null) continue;
|
||||
if (input.link == null) {
|
||||
continue;
|
||||
}
|
||||
var v = this.getInputData(i);
|
||||
if (v === undefined) continue;
|
||||
if (input.name == "gain")
|
||||
if (v === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (input.name == "gain") {
|
||||
this.audionode.gain.value = this.properties.gain = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioMediaSource.prototype.onAction = function(event) {
|
||||
if (event == "Play") this.audionode.gain.value = this.properties.gain;
|
||||
else if (event == "Stop") this.audionode.gain.value = 0;
|
||||
if (event == "Play") {
|
||||
this.audionode.gain.value = this.properties.gain;
|
||||
} else if (event == "Stop") {
|
||||
this.audionode.gain.value = 0;
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioMediaSource.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "gain") this.audionode.gain.value = value;
|
||||
if (name == "gain") {
|
||||
this.audionode.gain.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
//Helps connect/disconnect AudioNodes when new connections are made in the node
|
||||
@@ -573,8 +667,9 @@
|
||||
if (this.isOutputConnected(0)) {
|
||||
//send FFT
|
||||
var bufferLength = this.audionode.frequencyBinCount;
|
||||
if (!this._freq_bin || this._freq_bin.length != bufferLength)
|
||||
if (!this._freq_bin || this._freq_bin.length != bufferLength) {
|
||||
this._freq_bin = new Uint8Array(bufferLength);
|
||||
}
|
||||
this.audionode.getByteFrequencyData(this._freq_bin);
|
||||
this.setOutputData(0, this._freq_bin);
|
||||
}
|
||||
@@ -583,8 +678,9 @@
|
||||
if (this.isOutputConnected(1)) {
|
||||
//send Samples
|
||||
var bufferLength = this.audionode.frequencyBinCount;
|
||||
if (!this._time_bin || this._time_bin.length != bufferLength)
|
||||
if (!this._time_bin || this._time_bin.length != bufferLength) {
|
||||
this._time_bin = new Uint8Array(bufferLength);
|
||||
}
|
||||
this.audionode.getByteTimeDomainData(this._time_bin);
|
||||
this.setOutputData(1, this._time_bin);
|
||||
}
|
||||
@@ -592,9 +688,13 @@
|
||||
//properties
|
||||
for (var i = 1; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
if (input.link == null) continue;
|
||||
if (input.link == null) {
|
||||
continue;
|
||||
}
|
||||
var v = this.getInputData(i);
|
||||
if (v !== undefined) this.audionode[input.name].value = v;
|
||||
if (v !== undefined) {
|
||||
this.audionode[input.name].value = v;
|
||||
}
|
||||
}
|
||||
|
||||
//time domain
|
||||
@@ -632,12 +732,16 @@
|
||||
}
|
||||
|
||||
LGAudioGain.prototype.onExecute = function() {
|
||||
if (!this.inputs || !this.inputs.length) return;
|
||||
if (!this.inputs || !this.inputs.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 1; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
var v = this.getInputData(i);
|
||||
if (v !== undefined) this.audionode[input.name].value = v;
|
||||
if (v !== undefined) {
|
||||
this.audionode[input.name].value = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -662,16 +766,23 @@
|
||||
LGAudio.createAudioNodeWrapper(LGAudioConvolver);
|
||||
|
||||
LGAudioConvolver.prototype.onRemove = function() {
|
||||
if (this._dropped_url) URL.revokeObjectURL(this._dropped_url);
|
||||
if (this._dropped_url) {
|
||||
URL.revokeObjectURL(this._dropped_url);
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioConvolver.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "impulse_src") this.loadImpulse(value);
|
||||
else if (name == "normalize") this.audionode.normalize = value;
|
||||
if (name == "impulse_src") {
|
||||
this.loadImpulse(value);
|
||||
} else if (name == "normalize") {
|
||||
this.audionode.normalize = value;
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioConvolver.prototype.onDropFile = function(file) {
|
||||
if (this._dropped_url) URL.revokeObjectURL(this._dropped_url);
|
||||
if (this._dropped_url) {
|
||||
URL.revokeObjectURL(this._dropped_url);
|
||||
}
|
||||
this._dropped_url = URL.createObjectURL(file);
|
||||
this.properties.impulse_src = this._dropped_url;
|
||||
this.loadImpulse(this._dropped_url);
|
||||
@@ -689,7 +800,9 @@
|
||||
this._impulse_buffer = null;
|
||||
this._loading_impulse = false;
|
||||
|
||||
if (!url) return;
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
//load new sample
|
||||
this._request = LGAudio.loadSound(url, inner);
|
||||
@@ -727,12 +840,18 @@
|
||||
LGAudio.createAudioNodeWrapper(LGAudioDynamicsCompressor);
|
||||
|
||||
LGAudioDynamicsCompressor.prototype.onExecute = function() {
|
||||
if (!this.inputs || !this.inputs.length) return;
|
||||
if (!this.inputs || !this.inputs.length) {
|
||||
return;
|
||||
}
|
||||
for (var i = 1; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
if (input.link == null) continue;
|
||||
if (input.link == null) {
|
||||
continue;
|
||||
}
|
||||
var v = this.getInputData(i);
|
||||
if (v !== undefined) this.audionode[input.name].value = v;
|
||||
if (v !== undefined) {
|
||||
this.audionode[input.name].value = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -765,9 +884,13 @@
|
||||
}
|
||||
|
||||
LGAudioWaveShaper.prototype.onExecute = function() {
|
||||
if (!this.inputs || !this.inputs.length) return;
|
||||
if (!this.inputs || !this.inputs.length) {
|
||||
return;
|
||||
}
|
||||
var v = this.getInputData(1);
|
||||
if (v === undefined) return;
|
||||
if (v === undefined) {
|
||||
return;
|
||||
}
|
||||
this.audionode.curve = v;
|
||||
};
|
||||
|
||||
@@ -809,28 +932,43 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
}
|
||||
|
||||
LGAudioMixer.prototype.getAudioNodeInInputSlot = function(slot) {
|
||||
if (slot == 0) return this.audionode1;
|
||||
else if (slot == 2) return this.audionode2;
|
||||
if (slot == 0) {
|
||||
return this.audionode1;
|
||||
} else if (slot == 2) {
|
||||
return this.audionode2;
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioMixer.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "gain1") this.audionode1.gain.value = value;
|
||||
else if (name == "gain2") this.audionode2.gain.value = value;
|
||||
if (name == "gain1") {
|
||||
this.audionode1.gain.value = value;
|
||||
} else if (name == "gain2") {
|
||||
this.audionode2.gain.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioMixer.prototype.onExecute = function() {
|
||||
if (!this.inputs || !this.inputs.length) return;
|
||||
if (!this.inputs || !this.inputs.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 1; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
|
||||
if (input.link == null || input.type == "audio") continue;
|
||||
if (input.link == null || input.type == "audio") {
|
||||
continue;
|
||||
}
|
||||
|
||||
var v = this.getInputData(i);
|
||||
if (v === undefined) continue;
|
||||
if (v === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == 1) this.audionode1.gain.value = v;
|
||||
else if (i == 3) this.audionode2.gain.value = v;
|
||||
if (i == 1) {
|
||||
this.audionode1.gain.value = v;
|
||||
} else if (i == 3) {
|
||||
this.audionode2.gain.value = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -915,7 +1053,9 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
|
||||
LGAudioDelay.prototype.onExecute = function() {
|
||||
var v = this.getInputData(1);
|
||||
if (v !== undefined) this.audionode.delayTime.value = v;
|
||||
if (v !== undefined) {
|
||||
this.audionode.delayTime.value = v;
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioDelay.title = "Delay";
|
||||
@@ -951,13 +1091,19 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
}
|
||||
|
||||
LGAudioBiquadFilter.prototype.onExecute = function() {
|
||||
if (!this.inputs || !this.inputs.length) return;
|
||||
if (!this.inputs || !this.inputs.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 1; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
if (input.link == null) continue;
|
||||
if (input.link == null) {
|
||||
continue;
|
||||
}
|
||||
var v = this.getInputData(i);
|
||||
if (v !== undefined) this.audionode[input.name].value = v;
|
||||
if (v !== undefined) {
|
||||
this.audionode[input.name].value = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1014,13 +1160,19 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
};
|
||||
|
||||
LGAudioOscillatorNode.prototype.onExecute = function() {
|
||||
if (!this.inputs || !this.inputs.length) return;
|
||||
if (!this.inputs || !this.inputs.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
if (input.link == null) continue;
|
||||
if (input.link == null) {
|
||||
continue;
|
||||
}
|
||||
var v = this.getInputData(i);
|
||||
if (v !== undefined) this.audionode[input.name].value = v;
|
||||
if (v !== undefined) {
|
||||
this.audionode[input.name].value = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1057,12 +1209,16 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
LGAudioVisualization.prototype.onExecute = function() {
|
||||
this._last_buffer = this.getInputData(0);
|
||||
var v = this.getInputData(1);
|
||||
if (v !== undefined) this.properties.mark = v;
|
||||
if (v !== undefined) {
|
||||
this.properties.mark = v;
|
||||
}
|
||||
this.setDirtyCanvas(true, false);
|
||||
};
|
||||
|
||||
LGAudioVisualization.prototype.onDrawForeground = function(ctx) {
|
||||
if (!this._last_buffer) return;
|
||||
if (!this._last_buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer = this._last_buffer;
|
||||
|
||||
@@ -1095,7 +1251,9 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
var samplerate = LGAudio.getAudioContext().sampleRate;
|
||||
var binfreq = samplerate / buffer.length;
|
||||
var x = (2 * (this.properties.mark / binfreq)) / delta;
|
||||
if (x >= this.size[0]) x = this.size[0] - 1;
|
||||
if (x >= this.size[0]) {
|
||||
x = this.size[0] - 1;
|
||||
}
|
||||
ctx.strokeStyle = "red";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x, h);
|
||||
@@ -1121,20 +1279,26 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
|
||||
LGAudioBandSignal.prototype.onExecute = function() {
|
||||
this._freqs = this.getInputData(0);
|
||||
if (!this._freqs) return;
|
||||
if (!this._freqs) {
|
||||
return;
|
||||
}
|
||||
|
||||
var band = this.properties.band;
|
||||
var v = this.getInputData(1);
|
||||
if (v !== undefined) band = v;
|
||||
if (v !== undefined) {
|
||||
band = v;
|
||||
}
|
||||
|
||||
var samplerate = LGAudio.getAudioContext().sampleRate;
|
||||
var binfreq = samplerate / this._freqs.length;
|
||||
var index = 2 * (band / binfreq);
|
||||
var v = 0;
|
||||
if (index < 0) v = this._freqs[0];
|
||||
if (index >= this._freqs.length)
|
||||
if (index < 0) {
|
||||
v = this._freqs[0];
|
||||
}
|
||||
if (index >= this._freqs.length) {
|
||||
v = this._freqs[this._freqs.length - 1];
|
||||
else {
|
||||
} else {
|
||||
var pos = index | 0;
|
||||
var v0 = this._freqs[pos];
|
||||
var v1 = this._freqs[pos + 1];
|
||||
@@ -1168,8 +1332,9 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
|
||||
//create node
|
||||
var ctx = LGAudio.getAudioContext();
|
||||
if (ctx.createScriptProcessor)
|
||||
if (ctx.createScriptProcessor) {
|
||||
this.audionode = ctx.createScriptProcessor(4096, 1, 1);
|
||||
}
|
||||
//buffer size, input channels, output channels
|
||||
else {
|
||||
console.warn("ScriptProcessorNode deprecated");
|
||||
@@ -1177,8 +1342,9 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
}
|
||||
|
||||
this.processCode();
|
||||
if (!LGAudioScript._bypass_function)
|
||||
if (!LGAudioScript._bypass_function) {
|
||||
LGAudioScript._bypass_function = this.audionode.onaudioprocess;
|
||||
}
|
||||
|
||||
//slots
|
||||
this.addInput("in", "audio");
|
||||
@@ -1186,8 +1352,9 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
}
|
||||
|
||||
LGAudioScript.prototype.onAdded = function(graph) {
|
||||
if (graph.status == LGraph.STATUS_RUNNING)
|
||||
if (graph.status == LGraph.STATUS_RUNNING) {
|
||||
this.audionode.onaudioprocess = this._callback;
|
||||
}
|
||||
};
|
||||
|
||||
LGAudioScript["@code"] = { widget: "code" };
|
||||
@@ -1233,8 +1400,9 @@ LiteGraph.registerNodeType("audio/waveShaper", LGAudioWaveShaper);
|
||||
if (name == "code") {
|
||||
this.properties.code = value;
|
||||
this.processCode();
|
||||
if (this.graph && this.graph.status == LGraph.STATUS_RUNNING)
|
||||
if (this.graph && this.graph.status == LGraph.STATUS_RUNNING) {
|
||||
this.audionode.onaudioprocess = this._callback;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -56,7 +56,9 @@
|
||||
};
|
||||
|
||||
Subgraph.prototype.onDrawTitle = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.fillStyle = "#555";
|
||||
var w = LiteGraph.NODE_TITLE_HEIGHT;
|
||||
@@ -96,89 +98,111 @@
|
||||
|
||||
Subgraph.prototype.onExecute = function() {
|
||||
this.enabled = this.getInputOrProperty("enabled");
|
||||
if (!this.enabled) return;
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
//send inputs to subgraph global inputs
|
||||
if (this.inputs)
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; i++) {
|
||||
var input = this.inputs[i];
|
||||
var value = this.getInputData(i);
|
||||
this.subgraph.setInputData(input.name, value);
|
||||
}
|
||||
}
|
||||
|
||||
//execute
|
||||
this.subgraph.runStep();
|
||||
|
||||
//send subgraph global outputs to outputs
|
||||
if (this.outputs)
|
||||
if (this.outputs) {
|
||||
for (var i = 0; i < this.outputs.length; i++) {
|
||||
var output = this.outputs[i];
|
||||
var value = this.subgraph.getOutputData(output.name);
|
||||
this.setOutputData(i, value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Subgraph.prototype.sendEventToAllNodes = function(eventname, param, mode) {
|
||||
if (this.enabled)
|
||||
if (this.enabled) {
|
||||
this.subgraph.sendEventToAllNodes(eventname, param, mode);
|
||||
}
|
||||
};
|
||||
|
||||
//**** INPUTS ***********************************
|
||||
Subgraph.prototype.onSubgraphTrigger = function(event, param) {
|
||||
var slot = this.findOutputSlot(event);
|
||||
if (slot != -1) this.triggerSlot(slot);
|
||||
if (slot != -1) {
|
||||
this.triggerSlot(slot);
|
||||
}
|
||||
};
|
||||
|
||||
Subgraph.prototype.onSubgraphNewInput = function(name, type) {
|
||||
var slot = this.findInputSlot(name);
|
||||
if (slot == -1)
|
||||
if (slot == -1) {
|
||||
//add input to the node
|
||||
this.addInput(name, type);
|
||||
}
|
||||
};
|
||||
|
||||
Subgraph.prototype.onSubgraphRenamedInput = function(oldname, name) {
|
||||
var slot = this.findInputSlot(oldname);
|
||||
if (slot == -1) return;
|
||||
if (slot == -1) {
|
||||
return;
|
||||
}
|
||||
var info = this.getInputInfo(slot);
|
||||
info.name = name;
|
||||
};
|
||||
|
||||
Subgraph.prototype.onSubgraphTypeChangeInput = function(name, type) {
|
||||
var slot = this.findInputSlot(name);
|
||||
if (slot == -1) return;
|
||||
if (slot == -1) {
|
||||
return;
|
||||
}
|
||||
var info = this.getInputInfo(slot);
|
||||
info.type = type;
|
||||
};
|
||||
|
||||
Subgraph.prototype.onSubgraphRemovedInput = function(name) {
|
||||
var slot = this.findInputSlot(name);
|
||||
if (slot == -1) return;
|
||||
if (slot == -1) {
|
||||
return;
|
||||
}
|
||||
this.removeInput(slot);
|
||||
};
|
||||
|
||||
//**** OUTPUTS ***********************************
|
||||
Subgraph.prototype.onSubgraphNewOutput = function(name, type) {
|
||||
var slot = this.findOutputSlot(name);
|
||||
if (slot == -1) this.addOutput(name, type);
|
||||
if (slot == -1) {
|
||||
this.addOutput(name, type);
|
||||
}
|
||||
};
|
||||
|
||||
Subgraph.prototype.onSubgraphRenamedOutput = function(oldname, name) {
|
||||
var slot = this.findOutputSlot(oldname);
|
||||
if (slot == -1) return;
|
||||
if (slot == -1) {
|
||||
return;
|
||||
}
|
||||
var info = this.getOutputInfo(slot);
|
||||
info.name = name;
|
||||
};
|
||||
|
||||
Subgraph.prototype.onSubgraphTypeChangeOutput = function(name, type) {
|
||||
var slot = this.findOutputSlot(name);
|
||||
if (slot == -1) return;
|
||||
if (slot == -1) {
|
||||
return;
|
||||
}
|
||||
var info = this.getOutputInfo(slot);
|
||||
info.type = type;
|
||||
};
|
||||
|
||||
Subgraph.prototype.onSubgraphRemovedOutput = function(name) {
|
||||
var slot = this.findInputSlot(name);
|
||||
if (slot == -1) return;
|
||||
if (slot == -1) {
|
||||
return;
|
||||
}
|
||||
this.removeOutput(slot);
|
||||
};
|
||||
// *****************************************************
|
||||
@@ -232,12 +256,15 @@
|
||||
return that.name_in_graph;
|
||||
},
|
||||
set: function(v) {
|
||||
if (v == "" || v == that.name_in_graph || v == "enabled")
|
||||
if (v == "" || v == that.name_in_graph || v == "enabled") {
|
||||
return;
|
||||
if (that.name_in_graph)
|
||||
}
|
||||
if (that.name_in_graph) {
|
||||
//already added
|
||||
that.graph.renameInput(that.name_in_graph, v);
|
||||
else that.graph.addInput(v, that.properties.type);
|
||||
} else {
|
||||
that.graph.addInput(v, that.properties.type);
|
||||
}
|
||||
that.name_widget.value = v;
|
||||
that.name_in_graph = v;
|
||||
},
|
||||
@@ -249,14 +276,17 @@
|
||||
return that.outputs[0].type;
|
||||
},
|
||||
set: function(v) {
|
||||
if (v == "event") v = LiteGraph.EVENT;
|
||||
if (v == "event") {
|
||||
v = LiteGraph.EVENT;
|
||||
}
|
||||
that.outputs[0].type = v;
|
||||
if (that.name_in_graph)
|
||||
if (that.name_in_graph) {
|
||||
//already added
|
||||
that.graph.changeInputType(
|
||||
that.name_in_graph,
|
||||
that.outputs[0].type
|
||||
);
|
||||
}
|
||||
that.type_widget.value = v;
|
||||
},
|
||||
enumerable: true
|
||||
@@ -267,7 +297,9 @@
|
||||
"Name",
|
||||
this.properties.name,
|
||||
function(v) {
|
||||
if (!v) return;
|
||||
if (!v) {
|
||||
return;
|
||||
}
|
||||
that.properties.name = v;
|
||||
}
|
||||
);
|
||||
@@ -289,12 +321,16 @@
|
||||
GraphInput.desc = "Input of the graph";
|
||||
|
||||
GraphInput.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return this.properties.name;
|
||||
if (this.flags.collapsed) {
|
||||
return this.properties.name;
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
GraphInput.prototype.onAction = function(action, param) {
|
||||
if (this.properties.type == LiteGraph.EVENT) this.triggerSlot(0, param);
|
||||
if (this.properties.type == LiteGraph.EVENT) {
|
||||
this.triggerSlot(0, param);
|
||||
}
|
||||
};
|
||||
|
||||
GraphInput.prototype.onExecute = function() {
|
||||
@@ -302,14 +338,18 @@
|
||||
|
||||
//read from global input
|
||||
var data = this.graph.inputs[name];
|
||||
if (!data) return;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
//put through output
|
||||
this.setOutputData(0, data.value);
|
||||
};
|
||||
|
||||
GraphInput.prototype.onRemoved = function() {
|
||||
if (this.name_in_graph) this.graph.removeInput(this.name_in_graph);
|
||||
if (this.name_in_graph) {
|
||||
this.graph.removeInput(this.name_in_graph);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.GraphInput = GraphInput;
|
||||
@@ -328,11 +368,15 @@
|
||||
return that.name_in_graph;
|
||||
},
|
||||
set: function(v) {
|
||||
if (v == "" || v == that.name_in_graph) return;
|
||||
if (that.name_in_graph)
|
||||
if (v == "" || v == that.name_in_graph) {
|
||||
return;
|
||||
}
|
||||
if (that.name_in_graph) {
|
||||
//already added
|
||||
that.graph.renameOutput(that.name_in_graph, v);
|
||||
else that.graph.addOutput(v, that.properties.type);
|
||||
} else {
|
||||
that.graph.addOutput(v, that.properties.type);
|
||||
}
|
||||
that.name_widget.value = v;
|
||||
that.name_in_graph = v;
|
||||
},
|
||||
@@ -344,14 +388,17 @@
|
||||
return that.inputs[0].type;
|
||||
},
|
||||
set: function(v) {
|
||||
if (v == "action" || v == "event") v = LiteGraph.ACTION;
|
||||
if (v == "action" || v == "event") {
|
||||
v = LiteGraph.ACTION;
|
||||
}
|
||||
that.inputs[0].type = v;
|
||||
if (that.name_in_graph)
|
||||
if (that.name_in_graph) {
|
||||
//already added
|
||||
that.graph.changeOutputType(
|
||||
that.name_in_graph,
|
||||
that.inputs[0].type
|
||||
);
|
||||
}
|
||||
that.type_widget.value = v || "";
|
||||
},
|
||||
enumerable: true
|
||||
@@ -362,7 +409,9 @@
|
||||
"Name",
|
||||
this.properties.name,
|
||||
function(v) {
|
||||
if (!v) return;
|
||||
if (!v) {
|
||||
return;
|
||||
}
|
||||
that.properties.name = v;
|
||||
}
|
||||
);
|
||||
@@ -389,16 +438,21 @@
|
||||
};
|
||||
|
||||
GraphOutput.prototype.onAction = function(action, param) {
|
||||
if (this.properties.type == LiteGraph.ACTION)
|
||||
if (this.properties.type == LiteGraph.ACTION) {
|
||||
this.graph.trigger(this.properties.name, param);
|
||||
}
|
||||
};
|
||||
|
||||
GraphOutput.prototype.onRemoved = function() {
|
||||
if (this.name_in_graph) this.graph.removeOutput(this.name_in_graph);
|
||||
if (this.name_in_graph) {
|
||||
this.graph.removeOutput(this.name_in_graph);
|
||||
}
|
||||
};
|
||||
|
||||
GraphOutput.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return this.properties.name;
|
||||
if (this.flags.collapsed) {
|
||||
return this.properties.name;
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
@@ -419,7 +473,9 @@
|
||||
};
|
||||
|
||||
ConstantNumber.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return this.properties.value;
|
||||
if (this.flags.collapsed) {
|
||||
return this.properties.value;
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
@@ -490,7 +546,9 @@
|
||||
|
||||
ConstantData.prototype.onPropertyChanged = function(name, value) {
|
||||
this.widget.value = value;
|
||||
if (value == null || value == "") return;
|
||||
if (value == null || value == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this._value = JSON.parse(value);
|
||||
@@ -530,7 +588,9 @@
|
||||
};
|
||||
|
||||
ObjectProperty.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return "in." + this.properties.value;
|
||||
if (this.flags.collapsed) {
|
||||
return "in." + this.properties.value;
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
@@ -540,7 +600,9 @@
|
||||
|
||||
ObjectProperty.prototype.onExecute = function() {
|
||||
var data = this.getInputData(0);
|
||||
if (data != null) this.setOutputData(0, data[this.properties.value]);
|
||||
if (data != null) {
|
||||
this.setOutputData(0, data[this.properties.value]);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("basic/object_property", ObjectProperty);
|
||||
@@ -556,24 +618,33 @@
|
||||
Watch.desc = "Show value of input";
|
||||
|
||||
Watch.prototype.onExecute = function() {
|
||||
if (this.inputs[0]) this.value = this.getInputData(0);
|
||||
if (this.inputs[0]) {
|
||||
this.value = this.getInputData(0);
|
||||
}
|
||||
};
|
||||
|
||||
Watch.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return this.inputs[0].label;
|
||||
if (this.flags.collapsed) {
|
||||
return this.inputs[0].label;
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
Watch.toString = function(o) {
|
||||
if (o == null) return "null";
|
||||
else if (o.constructor === Number) return o.toFixed(3);
|
||||
else if (o.constructor === Array) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
} else if (o.constructor === Number) {
|
||||
return o.toFixed(3);
|
||||
} else if (o.constructor === Array) {
|
||||
var str = "[";
|
||||
for (var i = 0; i < o.length; ++i)
|
||||
for (var i = 0; i < o.length; ++i) {
|
||||
str += Watch.toString(o[i]) + (i + 1 != o.length ? "," : "");
|
||||
}
|
||||
str += "]";
|
||||
return str;
|
||||
} else return String(o);
|
||||
} else {
|
||||
return String(o);
|
||||
}
|
||||
};
|
||||
|
||||
Watch.prototype.onDrawBackground = function(ctx) {
|
||||
@@ -612,14 +683,20 @@
|
||||
Console.desc = "Show value inside the console";
|
||||
|
||||
Console.prototype.onAction = function(action, param) {
|
||||
if (action == "log") console.log(param);
|
||||
else if (action == "warn") console.warn(param);
|
||||
else if (action == "error") console.error(param);
|
||||
if (action == "log") {
|
||||
console.log(param);
|
||||
} else if (action == "warn") {
|
||||
console.warn(param);
|
||||
} else if (action == "error") {
|
||||
console.error(param);
|
||||
}
|
||||
};
|
||||
|
||||
Console.prototype.onExecute = function() {
|
||||
var msg = this.getInputData(1);
|
||||
if (msg !== null) this.properties.msg = msg;
|
||||
if (msg !== null) {
|
||||
this.properties.msg = msg;
|
||||
}
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
@@ -676,7 +753,9 @@
|
||||
}
|
||||
|
||||
NodeScript.prototype.onConfigure = function(o) {
|
||||
if (o.properties.onExecute) this.compileCode(o.properties.onExecute);
|
||||
if (o.properties.onExecute) {
|
||||
this.compileCode(o.properties.onExecute);
|
||||
}
|
||||
};
|
||||
|
||||
NodeScript.title = "Script";
|
||||
@@ -694,8 +773,9 @@
|
||||
|
||||
NodeScript.prototype.compileCode = function(code) {
|
||||
this._func = null;
|
||||
if (code.length > 100) console.warn("Script too long, max 100 chars");
|
||||
else {
|
||||
if (code.length > 100) {
|
||||
console.warn("Script too long, max 100 chars");
|
||||
} else {
|
||||
var code_low = code.toLowerCase();
|
||||
var forbidden_words = [
|
||||
"script",
|
||||
@@ -705,11 +785,12 @@
|
||||
"nodescript",
|
||||
"function"
|
||||
]; //bad security solution
|
||||
for (var i = 0; i < forbidden_words.length; ++i)
|
||||
for (var i = 0; i < forbidden_words.length; ++i) {
|
||||
if (code_low.indexOf(forbidden_words[i]) != -1) {
|
||||
console.warn("invalid script");
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
this._func = new Function("A", "B", "C", "DATA", "node", code);
|
||||
} catch (err) {
|
||||
@@ -720,7 +801,9 @@
|
||||
};
|
||||
|
||||
NodeScript.prototype.onExecute = function() {
|
||||
if (!this._func) return;
|
||||
if (!this._func) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var A = this.getInputData(0);
|
||||
@@ -738,4 +821,4 @@
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("basic/script", NodeScript);
|
||||
})(this);
|
||||
})(this);
|
||||
|
||||
@@ -43,9 +43,11 @@
|
||||
};
|
||||
|
||||
Sequencer.prototype.onAction = function(action, param) {
|
||||
if (this.outputs)
|
||||
for (var i = 0; i < this.outputs.length; ++i)
|
||||
if (this.outputs) {
|
||||
for (var i = 0; i < this.outputs.length; ++i) {
|
||||
this.triggerSlot(i, param);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("events/sequencer", Sequencer);
|
||||
@@ -66,20 +68,26 @@
|
||||
FilterEvent.desc = "Blocks events that do not match the filter";
|
||||
|
||||
FilterEvent.prototype.onAction = function(action, param) {
|
||||
if (param == null) return;
|
||||
|
||||
if (this.properties.equal_to && this.properties.equal_to != param)
|
||||
if (param == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.properties.equal_to && this.properties.equal_to != param) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.properties.has_property) {
|
||||
var prop = param[this.properties.has_property];
|
||||
if (prop == null) return;
|
||||
if (prop == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
this.properties.property_equal_to &&
|
||||
this.properties.property_equal_to != prop
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.triggerSlot(0, param);
|
||||
@@ -101,20 +109,30 @@
|
||||
EventCounter.desc = "Counts events";
|
||||
|
||||
EventCounter.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return String(this.num);
|
||||
if (this.flags.collapsed) {
|
||||
return String(this.num);
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
EventCounter.prototype.onAction = function(action, param) {
|
||||
var v = this.num;
|
||||
if (action == "inc") this.num += 1;
|
||||
else if (action == "dec") this.num -= 1;
|
||||
else if (action == "reset") this.num = 0;
|
||||
if (this.num != v) this.trigger("change", this.num);
|
||||
if (action == "inc") {
|
||||
this.num += 1;
|
||||
} else if (action == "dec") {
|
||||
this.num -= 1;
|
||||
} else if (action == "reset") {
|
||||
this.num = 0;
|
||||
}
|
||||
if (this.num != v) {
|
||||
this.trigger("change", this.num);
|
||||
}
|
||||
};
|
||||
|
||||
EventCounter.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
ctx.fillStyle = "#AAA";
|
||||
ctx.font = "20px Arial";
|
||||
ctx.textAlign = "center";
|
||||
@@ -142,20 +160,26 @@
|
||||
|
||||
DelayEvent.prototype.onAction = function(action, param) {
|
||||
var time = this.properties.time_in_ms;
|
||||
if (time <= 0) this.trigger(null, param);
|
||||
else this._pending.push([time, param]);
|
||||
if (time <= 0) {
|
||||
this.trigger(null, param);
|
||||
} else {
|
||||
this._pending.push([time, param]);
|
||||
}
|
||||
};
|
||||
|
||||
DelayEvent.prototype.onExecute = function() {
|
||||
var dt = this.graph.elapsed_time * 1000; //in ms
|
||||
|
||||
if (this.isInputConnected(1))
|
||||
if (this.isInputConnected(1)) {
|
||||
this.properties.time_in_ms = this.getInputData(1);
|
||||
}
|
||||
|
||||
for (var i = 0; i < this._pending.length; ++i) {
|
||||
var action = this._pending[i];
|
||||
action[0] -= dt;
|
||||
if (action[0] > 0) continue;
|
||||
if (action[0] > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//remove
|
||||
this._pending.splice(i, 1);
|
||||
@@ -218,16 +242,18 @@
|
||||
!trigger &&
|
||||
(this.time < this.last_interval || isNaN(this.last_interval))
|
||||
) {
|
||||
if (this.inputs && this.inputs.length > 1 && this.inputs[1])
|
||||
if (this.inputs && this.inputs.length > 1 && this.inputs[1]) {
|
||||
this.setOutputData(1, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.triggered = true;
|
||||
this.time = this.time % this.last_interval;
|
||||
this.trigger("on_tick", this.properties.event);
|
||||
if (this.inputs && this.inputs.length > 1 && this.inputs[1])
|
||||
if (this.inputs && this.inputs.length > 1 && this.inputs[1]) {
|
||||
this.setOutputData(1, true);
|
||||
}
|
||||
};
|
||||
|
||||
TimerEvent.prototype.onGetInputs = function() {
|
||||
|
||||
@@ -45,7 +45,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tex) return;
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._tex = LGraphTexture.getTargetTexture(
|
||||
tex,
|
||||
@@ -272,10 +274,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (!blurred_tex) blurred_tex = tex;
|
||||
if (!blurred_tex) {
|
||||
blurred_tex = tex;
|
||||
}
|
||||
|
||||
var shape_tex = LGraphTexture.getTexture(this.properties.shape);
|
||||
if (!shape_tex) return;
|
||||
if (!shape_tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
var threshold = this.properties.threshold;
|
||||
if (this.isInputConnected(3)) {
|
||||
@@ -284,36 +290,40 @@
|
||||
}
|
||||
|
||||
var precision = gl.UNSIGNED_BYTE;
|
||||
if (this.properties.high_precision)
|
||||
if (this.properties.high_precision) {
|
||||
precision = gl.half_float_ext ? gl.HALF_FLOAT_OES : gl.FLOAT;
|
||||
}
|
||||
if (
|
||||
!this._temp_texture ||
|
||||
this._temp_texture.type != precision ||
|
||||
this._temp_texture.width != tex.width ||
|
||||
this._temp_texture.height != tex.height
|
||||
)
|
||||
) {
|
||||
this._temp_texture = new GL.Texture(tex.width, tex.height, {
|
||||
type: precision,
|
||||
format: gl.RGBA,
|
||||
filter: gl.LINEAR
|
||||
});
|
||||
}
|
||||
|
||||
//iterations
|
||||
var size = this.properties.size;
|
||||
|
||||
var first_shader = LGraphFXBokeh._first_shader;
|
||||
if (!first_shader)
|
||||
if (!first_shader) {
|
||||
first_shader = LGraphFXBokeh._first_shader = new GL.Shader(
|
||||
Shader.SCREEN_VERTEX_SHADER,
|
||||
LGraphFXBokeh._first_pixel_shader
|
||||
);
|
||||
}
|
||||
|
||||
var second_shader = LGraphFXBokeh._second_shader;
|
||||
if (!second_shader)
|
||||
if (!second_shader) {
|
||||
second_shader = LGraphFXBokeh._second_shader = new GL.Shader(
|
||||
LGraphFXBokeh._second_vertex_shader,
|
||||
LGraphFXBokeh._second_pixel_shader
|
||||
);
|
||||
}
|
||||
|
||||
var points_mesh = this._points_mesh;
|
||||
if (
|
||||
@@ -321,8 +331,9 @@
|
||||
points_mesh._width != tex.width ||
|
||||
points_mesh._height != tex.height ||
|
||||
points_mesh._spacing != 2
|
||||
)
|
||||
) {
|
||||
points_mesh = this.createPointsMesh(tex.width, tex.height, 2);
|
||||
}
|
||||
|
||||
var screen_mesh = Mesh.getScreenQuad();
|
||||
|
||||
@@ -506,7 +517,9 @@
|
||||
LGraphFXGeneric.shaders = {};
|
||||
|
||||
LGraphFXGeneric.prototype.onExecute = function() {
|
||||
if (!this.isOutputConnected(0)) return; //saves work
|
||||
if (!this.isOutputConnected(0)) {
|
||||
return;
|
||||
} //saves work
|
||||
|
||||
var tex = this.getInputData(0);
|
||||
if (this.properties.precision === LGraphTexture.PASS_THROUGH) {
|
||||
@@ -514,7 +527,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tex) return;
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._tex = LGraphTexture.getTargetTexture(
|
||||
tex,
|
||||
@@ -539,7 +554,9 @@
|
||||
var shader = LGraphFXGeneric.shaders[fx];
|
||||
if (!shader) {
|
||||
var pixel_shader_code = LGraphFXGeneric["pixel_shader_" + fx];
|
||||
if (!pixel_shader_code) return;
|
||||
if (!pixel_shader_code) {
|
||||
return;
|
||||
}
|
||||
|
||||
shader = LGraphFXGeneric.shaders[fx] = new GL.Shader(
|
||||
Shader.SCREEN_VERTEX_SHADER,
|
||||
@@ -552,19 +569,25 @@
|
||||
var mesh = Mesh.getScreenQuad();
|
||||
var camera = global.LS ? LS.Renderer._current_camera : null;
|
||||
var camera_planes;
|
||||
if (camera)
|
||||
if (camera) {
|
||||
camera_planes = [
|
||||
LS.Renderer._current_camera.near,
|
||||
LS.Renderer._current_camera.far
|
||||
];
|
||||
else camera_planes = [1, 100];
|
||||
} else {
|
||||
camera_planes = [1, 100];
|
||||
}
|
||||
|
||||
var noise = null;
|
||||
if (fx == "noise") noise = LGraphTexture.getNoiseTexture();
|
||||
if (fx == "noise") {
|
||||
noise = LGraphTexture.getNoiseTexture();
|
||||
}
|
||||
|
||||
this._tex.drawTo(function() {
|
||||
tex.bind(0);
|
||||
if (fx == "noise") noise.bind(1);
|
||||
if (fx == "noise") {
|
||||
noise.bind(1);
|
||||
}
|
||||
|
||||
shader
|
||||
.uniforms({
|
||||
@@ -679,11 +702,12 @@
|
||||
precision: LGraphTexture.DEFAULT
|
||||
};
|
||||
|
||||
if (!LGraphFXVigneting._shader)
|
||||
if (!LGraphFXVigneting._shader) {
|
||||
LGraphFXVigneting._shader = new GL.Shader(
|
||||
Shader.SCREEN_VERTEX_SHADER,
|
||||
LGraphFXVigneting.pixel_shader
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
LGraphFXVigneting.title = "Vigneting";
|
||||
@@ -701,7 +725,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tex) return;
|
||||
if (!tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._tex = LGraphTexture.getTargetTexture(
|
||||
tex,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,21 +16,29 @@
|
||||
GraphicsPlot.colors = ["#FFF", "#F99", "#9F9", "#99F"];
|
||||
|
||||
GraphicsPlot.prototype.onExecute = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
var size = this.size;
|
||||
|
||||
for (var i = 0; i < 4; ++i) {
|
||||
var v = this.getInputData(i);
|
||||
if (v == null) continue;
|
||||
if (v == null) {
|
||||
continue;
|
||||
}
|
||||
var values = this.values[i];
|
||||
values.push(v);
|
||||
if (values.length > size[0]) values.shift();
|
||||
if (values.length > size[0]) {
|
||||
values.shift();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GraphicsPlot.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
var size = this.size;
|
||||
|
||||
@@ -46,10 +54,12 @@
|
||||
ctx.lineTo(size[0], offset);
|
||||
ctx.stroke();
|
||||
|
||||
if (this.inputs)
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < 4; ++i) {
|
||||
var values = this.values[i];
|
||||
if (!this.inputs[i] || !this.inputs[i].link) continue;
|
||||
if (!this.inputs[i] || !this.inputs[i].link) {
|
||||
continue;
|
||||
}
|
||||
ctx.strokeStyle = colors[i];
|
||||
ctx.beginPath();
|
||||
var v = values[0] * scale * -1 + offset;
|
||||
@@ -60,6 +70,7 @@
|
||||
}
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("graphics/plot", GraphicsPlot);
|
||||
@@ -82,21 +93,33 @@
|
||||
};
|
||||
|
||||
GraphicsImage.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.img && this.size[0] > 5 && this.size[1] > 5)
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
if (this.img && this.size[0] > 5 && this.size[1] > 5) {
|
||||
ctx.drawImage(this.img, 0, 0, this.size[0], this.size[1]);
|
||||
}
|
||||
};
|
||||
|
||||
GraphicsImage.prototype.onExecute = function() {
|
||||
if (!this.img) this.boxcolor = "#000";
|
||||
if (this.img && this.img.width) this.setOutputData(0, this.img);
|
||||
else this.setOutputData(0, null);
|
||||
if (this.img && this.img.dirty) this.img.dirty = false;
|
||||
if (!this.img) {
|
||||
this.boxcolor = "#000";
|
||||
}
|
||||
if (this.img && this.img.width) {
|
||||
this.setOutputData(0, this.img);
|
||||
} else {
|
||||
this.setOutputData(0, null);
|
||||
}
|
||||
if (this.img && this.img.dirty) {
|
||||
this.img.dirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
GraphicsImage.prototype.onPropertyChanged = function(name, value) {
|
||||
this.properties[name] = value;
|
||||
if (name == "url" && value != "") this.loadImage(value);
|
||||
if (name == "url" && value != "") {
|
||||
this.loadImage(value);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
@@ -109,14 +132,17 @@
|
||||
|
||||
this.img = document.createElement("img");
|
||||
|
||||
if (url.substr(0, 4) == "http" && LiteGraph.proxy)
|
||||
if (url.substr(0, 4) == "http" && LiteGraph.proxy) {
|
||||
url = LiteGraph.proxy + url.substr(url.indexOf(":") + 3);
|
||||
}
|
||||
|
||||
this.img.src = url;
|
||||
this.boxcolor = "#F95";
|
||||
var that = this;
|
||||
this.img.onload = function() {
|
||||
if (callback) callback(this);
|
||||
if (callback) {
|
||||
callback(this);
|
||||
}
|
||||
that.trace(
|
||||
"Image loaded, size: " + that.img.width + "x" + that.img.height
|
||||
);
|
||||
@@ -134,7 +160,9 @@
|
||||
|
||||
GraphicsImage.prototype.onDropFile = function(file) {
|
||||
var that = this;
|
||||
if (this._url) URL.revokeObjectURL(this._url);
|
||||
if (this._url) {
|
||||
URL.revokeObjectURL(this._url);
|
||||
}
|
||||
this._url = URL.createObjectURL(file);
|
||||
this.properties.url = this._url;
|
||||
this.loadImage(this._url, function(img) {
|
||||
@@ -161,26 +189,39 @@
|
||||
ColorPalette.prototype.onExecute = function() {
|
||||
var c = [];
|
||||
|
||||
if (this.properties.colorA != null)
|
||||
if (this.properties.colorA != null) {
|
||||
c.push(hex2num(this.properties.colorA));
|
||||
if (this.properties.colorB != null)
|
||||
}
|
||||
if (this.properties.colorB != null) {
|
||||
c.push(hex2num(this.properties.colorB));
|
||||
if (this.properties.colorC != null)
|
||||
}
|
||||
if (this.properties.colorC != null) {
|
||||
c.push(hex2num(this.properties.colorC));
|
||||
if (this.properties.colorD != null)
|
||||
}
|
||||
if (this.properties.colorD != null) {
|
||||
c.push(hex2num(this.properties.colorD));
|
||||
}
|
||||
|
||||
var f = this.getInputData(0);
|
||||
if (f == null) f = 0.5;
|
||||
if (f > 1.0) f = 1.0;
|
||||
else if (f < 0.0) f = 0.0;
|
||||
if (f == null) {
|
||||
f = 0.5;
|
||||
}
|
||||
if (f > 1.0) {
|
||||
f = 1.0;
|
||||
} else if (f < 0.0) {
|
||||
f = 0.0;
|
||||
}
|
||||
|
||||
if (c.length == 0) return;
|
||||
if (c.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var result = [0, 0, 0];
|
||||
if (f == 0) result = c[0];
|
||||
else if (f == 1) result = c[c.length - 1];
|
||||
else {
|
||||
if (f == 0) {
|
||||
result = c[0];
|
||||
} else if (f == 1) {
|
||||
result = c[c.length - 1];
|
||||
} else {
|
||||
var pos = (c.length - 1) * f;
|
||||
var c1 = c[Math.floor(pos)];
|
||||
var c2 = c[Math.floor(pos) + 1];
|
||||
@@ -196,7 +237,9 @@
|
||||
c[2] = Math.abs( Math.sin( 0.01 * reModular.getTime() * Math.PI) );
|
||||
*/
|
||||
|
||||
for (var i in result) result[i] /= 255;
|
||||
for (var i in result) {
|
||||
result[i] /= 255;
|
||||
}
|
||||
|
||||
this.boxcolor = colorToString(result);
|
||||
this.setOutputData(0, result);
|
||||
@@ -217,8 +260,9 @@
|
||||
];
|
||||
|
||||
ImageFrame.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.frame && !this.flags.collapsed)
|
||||
if (this.frame && !this.flags.collapsed) {
|
||||
ctx.drawImage(this.frame, 0, 0, this.size[0], this.size[1]);
|
||||
}
|
||||
};
|
||||
|
||||
ImageFrame.prototype.onExecute = function() {
|
||||
@@ -236,14 +280,20 @@
|
||||
height = this.frame.videoHeight;
|
||||
}
|
||||
|
||||
if (width && height) this.size = [width, height];
|
||||
if (width && height) {
|
||||
this.size = [width, height];
|
||||
}
|
||||
this.setDirtyCanvas(true, true);
|
||||
} else if (widget.name == "view") this.show();
|
||||
} else if (widget.name == "view") {
|
||||
this.show();
|
||||
}
|
||||
};
|
||||
|
||||
ImageFrame.prototype.show = function() {
|
||||
//var str = this.canvas.toDataURL("image/png");
|
||||
if (showElement && this.frame) showElement(this.frame);
|
||||
if (showElement && this.frame) {
|
||||
showElement(this.frame);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("graphics/frame", ImageFrame);
|
||||
@@ -288,8 +338,11 @@
|
||||
}
|
||||
|
||||
var fade = this.getInputData(2);
|
||||
if (fade == null) fade = this.properties["fade"];
|
||||
else this.properties["fade"] = fade;
|
||||
if (fade == null) {
|
||||
fade = this.properties["fade"];
|
||||
} else {
|
||||
this.properties["fade"] = fade;
|
||||
}
|
||||
|
||||
ctx.globalAlpha = fade;
|
||||
var B = this.getInputData(1);
|
||||
@@ -326,7 +379,9 @@
|
||||
|
||||
ImageCrop.prototype.onExecute = function() {
|
||||
var input = this.getInputData(0);
|
||||
if (!input) return;
|
||||
if (!input) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.width) {
|
||||
var ctx = this.canvas.getContext("2d");
|
||||
@@ -339,12 +394,16 @@
|
||||
input.height * this.properties["scale"]
|
||||
);
|
||||
this.setOutputData(0, this.canvas);
|
||||
} else this.setOutputData(0, null);
|
||||
} else {
|
||||
this.setOutputData(0, null);
|
||||
}
|
||||
};
|
||||
|
||||
ImageCrop.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.canvas)
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
if (this.canvas) {
|
||||
ctx.drawImage(
|
||||
this.canvas,
|
||||
0,
|
||||
@@ -356,6 +415,7 @@
|
||||
this.size[0],
|
||||
this.size[1]
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
ImageCrop.prototype.onPropertyChanged = function(name, value) {
|
||||
@@ -367,7 +427,9 @@
|
||||
this.trace("Error in scale");
|
||||
this.properties[name] = 1.0;
|
||||
}
|
||||
} else this.properties[name] = parseInt(value);
|
||||
} else {
|
||||
this.properties[name] = parseInt(value);
|
||||
}
|
||||
|
||||
this.createCanvas();
|
||||
|
||||
@@ -394,17 +456,23 @@
|
||||
var canvas = this.canvas;
|
||||
var w = this.properties.width | 0;
|
||||
var h = this.properties.height | 0;
|
||||
if (canvas.width != w) canvas.width = w;
|
||||
if (canvas.height != h) canvas.height = h;
|
||||
if (canvas.width != w) {
|
||||
canvas.width = w;
|
||||
}
|
||||
if (canvas.height != h) {
|
||||
canvas.height = h;
|
||||
}
|
||||
|
||||
if (this.properties.autoclear)
|
||||
if (this.properties.autoclear) {
|
||||
this.ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
this.setOutputData(0, canvas);
|
||||
};
|
||||
|
||||
CanvasNode.prototype.onAction = function(action, param) {
|
||||
if (action == "clear")
|
||||
if (action == "clear") {
|
||||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("graphics/canvas", CanvasNode);
|
||||
@@ -422,10 +490,14 @@
|
||||
|
||||
DrawImageNode.prototype.onExecute = function() {
|
||||
var canvas = this.getInputData(0);
|
||||
if (!canvas) return;
|
||||
if (!canvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
var img = this.getInputOrProperty("img");
|
||||
if (!img) return;
|
||||
if (!img) {
|
||||
return;
|
||||
}
|
||||
|
||||
var x = this.getInputOrProperty("x");
|
||||
var y = this.getInputOrProperty("y");
|
||||
@@ -456,7 +528,9 @@
|
||||
|
||||
DrawRectangleNode.prototype.onExecute = function() {
|
||||
var canvas = this.getInputData(0);
|
||||
if (!canvas) return;
|
||||
if (!canvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
var x = this.getInputOrProperty("x");
|
||||
var y = this.getInputOrProperty("y");
|
||||
@@ -484,12 +558,17 @@
|
||||
];
|
||||
|
||||
ImageVideo.prototype.onExecute = function() {
|
||||
if (!this.properties.url) return;
|
||||
if (!this.properties.url) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.properties.url != this._video_url)
|
||||
if (this.properties.url != this._video_url) {
|
||||
this.loadVideo(this.properties.url);
|
||||
}
|
||||
|
||||
if (!this._video || this._video.width == 0) return;
|
||||
if (!this._video || this._video.width == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var t = this.getInputData(0);
|
||||
if (t && t >= 0 && t <= 1.0) {
|
||||
@@ -519,8 +598,9 @@
|
||||
this.properties.use_proxy &&
|
||||
url.substr(0, 4) == "http" &&
|
||||
LiteGraph.proxy
|
||||
)
|
||||
) {
|
||||
url = LiteGraph.proxy + url.substr(url.indexOf(":") + 3);
|
||||
}
|
||||
|
||||
this._video = document.createElement("video");
|
||||
this._video.src = url;
|
||||
@@ -575,29 +655,42 @@
|
||||
|
||||
ImageVideo.prototype.onPropertyChanged = function(name, value) {
|
||||
this.properties[name] = value;
|
||||
if (name == "url" && value != "") this.loadVideo(value);
|
||||
if (name == "url" && value != "") {
|
||||
this.loadVideo(value);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
ImageVideo.prototype.play = function() {
|
||||
if (this._video) this._video.play();
|
||||
if (this._video) {
|
||||
this._video.play();
|
||||
}
|
||||
};
|
||||
|
||||
ImageVideo.prototype.playPause = function() {
|
||||
if (!this._video) return;
|
||||
if (this._video.paused) this.play();
|
||||
else this.pause();
|
||||
if (!this._video) {
|
||||
return;
|
||||
}
|
||||
if (this._video.paused) {
|
||||
this.play();
|
||||
} else {
|
||||
this.pause();
|
||||
}
|
||||
};
|
||||
|
||||
ImageVideo.prototype.stop = function() {
|
||||
if (!this._video) return;
|
||||
if (!this._video) {
|
||||
return;
|
||||
}
|
||||
this._video.pause();
|
||||
this._video.currentTime = 0;
|
||||
};
|
||||
|
||||
ImageVideo.prototype.pause = function() {
|
||||
if (!this._video) return;
|
||||
if (!this._video) {
|
||||
return;
|
||||
}
|
||||
this.trace("Video paused");
|
||||
this._video.pause();
|
||||
};
|
||||
@@ -671,7 +764,9 @@
|
||||
if (this._webcam_stream) {
|
||||
var tracks = this._webcam_stream.getTracks();
|
||||
if (tracks.length) {
|
||||
for (var i = 0; i < tracks.length; ++i) tracks[i].stop();
|
||||
for (var i = 0; i < tracks.length; ++i) {
|
||||
tracks[i].stop();
|
||||
}
|
||||
}
|
||||
ImageWebcam.is_webcam_open = false;
|
||||
this._webcam_stream = null;
|
||||
@@ -717,17 +812,22 @@
|
||||
};
|
||||
|
||||
ImageWebcam.prototype.onExecute = function() {
|
||||
if (this._webcam_stream == null && !this._waiting_confirmation)
|
||||
if (this._webcam_stream == null && !this._waiting_confirmation) {
|
||||
this.openStream();
|
||||
}
|
||||
|
||||
if (!this._video || !this._video.videoWidth) return;
|
||||
if (!this._video || !this._video.videoWidth) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._video.frame = ++this.frame;
|
||||
this._video.width = this._video.videoWidth;
|
||||
this._video.height = this._video.videoHeight;
|
||||
this.setOutputData(0, this._video);
|
||||
for (var i = 1; i < this.outputs.length; ++i) {
|
||||
if (!this.outputs[i]) continue;
|
||||
if (!this.outputs[i]) {
|
||||
continue;
|
||||
}
|
||||
switch (this.outputs[i].name) {
|
||||
case "width":
|
||||
this.setOutputData(i, this._video.videoWidth);
|
||||
@@ -753,10 +853,17 @@
|
||||
};
|
||||
|
||||
ImageWebcam.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed || this.size[1] <= 20 || !this.properties.show)
|
||||
if (
|
||||
this.flags.collapsed ||
|
||||
this.size[1] <= 20 ||
|
||||
!this.properties.show
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._video) return;
|
||||
if (!this._video) {
|
||||
return;
|
||||
}
|
||||
|
||||
//render to graph canvas
|
||||
ctx.save();
|
||||
|
||||
@@ -75,7 +75,9 @@
|
||||
if (this.outputs) {
|
||||
for (var i = 0; i < this.outputs.length; i++) {
|
||||
var output = this.outputs[i];
|
||||
if (!output.links || !output.links.length) continue;
|
||||
if (!output.links || !output.links.length) {
|
||||
continue;
|
||||
}
|
||||
var v = null;
|
||||
|
||||
if (gamepad) {
|
||||
@@ -158,11 +160,12 @@
|
||||
if (
|
||||
this._current_buttons[j] &&
|
||||
!this._previous_buttons[j]
|
||||
)
|
||||
) {
|
||||
this.triggerSlot(
|
||||
i,
|
||||
GamepadInput.buttons[j]
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -191,7 +194,9 @@
|
||||
navigator.getGamepads ||
|
||||
navigator.webkitGetGamepads ||
|
||||
navigator.mozGetGamepads;
|
||||
if (!getGamepads) return null;
|
||||
if (!getGamepads) {
|
||||
return null;
|
||||
}
|
||||
var gamepads = getGamepads.call(navigator);
|
||||
var gamepad = null;
|
||||
|
||||
@@ -199,18 +204,21 @@
|
||||
|
||||
//pick the first connected
|
||||
for (var i = this.properties.gamepad_index; i < 4; i++) {
|
||||
if (!gamepads[i]) continue;
|
||||
if (!gamepads[i]) {
|
||||
continue;
|
||||
}
|
||||
gamepad = gamepads[i];
|
||||
|
||||
//xbox controller mapping
|
||||
var xbox = this.xbox_mapping;
|
||||
if (!xbox)
|
||||
if (!xbox) {
|
||||
xbox = this.xbox_mapping = {
|
||||
axes: [],
|
||||
buttons: {},
|
||||
hat: "",
|
||||
hatmap: GamepadInput.CENTER
|
||||
};
|
||||
}
|
||||
|
||||
xbox.axes["lx"] = gamepad.axes[0];
|
||||
xbox.axes["ly"] = gamepad.axes[1];
|
||||
@@ -300,7 +308,9 @@
|
||||
};
|
||||
|
||||
GamepadInput.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
//render gamepad state?
|
||||
var la = this._left_axis;
|
||||
@@ -321,8 +331,11 @@
|
||||
);
|
||||
var h = this.size[1] / this._current_buttons.length;
|
||||
ctx.fillStyle = "#AEB";
|
||||
for (var i = 0; i < this._current_buttons.length; ++i)
|
||||
if (this._current_buttons[i]) ctx.fillRect(0, h * i, 6, h);
|
||||
for (var i = 0; i < this._current_buttons.length; ++i) {
|
||||
if (this._current_buttons[i]) {
|
||||
ctx.fillRect(0, h * i, 6, h);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GamepadInput.prototype.onGetOutputs = function() {
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
|
||||
WidgetButton.font = "Arial";
|
||||
WidgetButton.prototype.onDrawForeground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
var margin = 10;
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillRect(
|
||||
@@ -97,7 +99,9 @@
|
||||
WidgetToggle.desc = "Toggles between true or false";
|
||||
|
||||
WidgetToggle.prototype.onDrawForeground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
var size = this.size[1] * 0.5;
|
||||
var margin = 0.25;
|
||||
@@ -130,7 +134,9 @@
|
||||
|
||||
WidgetToggle.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v != null) this.properties.value = v;
|
||||
if (v != null) {
|
||||
this.properties.value = v;
|
||||
}
|
||||
this.setOutputData(0, this.properties.value);
|
||||
};
|
||||
|
||||
@@ -184,7 +190,9 @@
|
||||
ctx.lineTo(x + h * -0.1, h * 0.8);
|
||||
ctx.fill();
|
||||
ctx.font = (h * 0.7).toFixed(1) + "px Arial";
|
||||
} else ctx.font = (h * 0.8).toFixed(1) + "px Arial";
|
||||
} else {
|
||||
ctx.font = (h * 0.8).toFixed(1) + "px Arial";
|
||||
}
|
||||
|
||||
ctx.textAlign = "center";
|
||||
ctx.font = (h * 0.7).toFixed(1) + "px Arial";
|
||||
@@ -206,7 +214,9 @@
|
||||
};
|
||||
|
||||
WidgetNumber.prototype.onMouseDown = function(e, pos) {
|
||||
if (pos[1] < 0) return;
|
||||
if (pos[1] < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.old_y = e.canvasY;
|
||||
this.captureInput(true);
|
||||
@@ -216,11 +226,17 @@
|
||||
};
|
||||
|
||||
WidgetNumber.prototype.onMouseMove = function(e) {
|
||||
if (!this.mouse_captured) return;
|
||||
if (!this.mouse_captured) {
|
||||
return;
|
||||
}
|
||||
|
||||
var delta = this.old_y - e.canvasY;
|
||||
if (e.shiftKey) delta *= 10;
|
||||
if (e.metaKey || e.altKey) delta *= 0.1;
|
||||
if (e.shiftKey) {
|
||||
delta *= 10;
|
||||
}
|
||||
if (e.metaKey || e.altKey) {
|
||||
delta *= 0.1;
|
||||
}
|
||||
this.old_y = e.canvasY;
|
||||
|
||||
var steps = this._remainder + delta / WidgetNumber.pixels_threshold;
|
||||
@@ -277,12 +293,15 @@
|
||||
WidgetKnob.size = [80, 100];
|
||||
|
||||
WidgetKnob.prototype.onDrawForeground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.value == -1)
|
||||
if (this.value == -1) {
|
||||
this.value =
|
||||
(this.properties.value - this.properties.min) /
|
||||
(this.properties.max - this.properties.min);
|
||||
}
|
||||
|
||||
var center_x = this.size[0] * 0.5;
|
||||
var center_y = this.size[1] * 0.5;
|
||||
@@ -370,22 +389,28 @@
|
||||
[e.canvasX, e.canvasY],
|
||||
[this.pos[0] + this.center[0], this.pos[1] + this.center[1]]
|
||||
) > this.radius
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
this.oldmouse = [e.canvasX - this.pos[0], e.canvasY - this.pos[1]];
|
||||
this.captureInput(true);
|
||||
return true;
|
||||
};
|
||||
|
||||
WidgetKnob.prototype.onMouseMove = function(e) {
|
||||
if (!this.oldmouse) return;
|
||||
if (!this.oldmouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
var m = [e.canvasX - this.pos[0], e.canvasY - this.pos[1]];
|
||||
|
||||
var v = this.value;
|
||||
v -= (m[1] - this.oldmouse[1]) * 0.01;
|
||||
if (v > 1.0) v = 1.0;
|
||||
else if (v < 0.0) v = 0.0;
|
||||
if (v > 1.0) {
|
||||
v = 1.0;
|
||||
} else if (v < 0.0) {
|
||||
v = 0.0;
|
||||
}
|
||||
this.value = v;
|
||||
this.properties.value =
|
||||
this.properties.min +
|
||||
@@ -436,7 +461,9 @@
|
||||
WidgetSliderGUI.title = "Inner Slider";
|
||||
|
||||
WidgetSliderGUI.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "value") this.slider.value = value;
|
||||
if (name == "value") {
|
||||
this.slider.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
WidgetSliderGUI.prototype.onExecute = function() {
|
||||
@@ -457,10 +484,11 @@
|
||||
WidgetHSlider.desc = "Linear slider controller";
|
||||
|
||||
WidgetHSlider.prototype.onDrawForeground = function(ctx) {
|
||||
if (this.value == -1)
|
||||
if (this.value == -1) {
|
||||
this.value =
|
||||
(this.properties.value - this.properties.min) /
|
||||
(this.properties.max - this.properties.min);
|
||||
}
|
||||
|
||||
//border
|
||||
ctx.globalAlpha = 1;
|
||||
@@ -487,7 +515,9 @@
|
||||
};
|
||||
|
||||
WidgetHSlider.prototype.onMouseDown = function(e) {
|
||||
if (e.canvasY - this.pos[1] < 0) return false;
|
||||
if (e.canvasY - this.pos[1] < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.oldmouse = [e.canvasX - this.pos[0], e.canvasY - this.pos[1]];
|
||||
this.captureInput(true);
|
||||
@@ -495,15 +525,20 @@
|
||||
};
|
||||
|
||||
WidgetHSlider.prototype.onMouseMove = function(e) {
|
||||
if (!this.oldmouse) return;
|
||||
if (!this.oldmouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
var m = [e.canvasX - this.pos[0], e.canvasY - this.pos[1]];
|
||||
|
||||
var v = this.value;
|
||||
var delta = m[0] - this.oldmouse[0];
|
||||
v += delta / this.size[0];
|
||||
if (v > 1.0) v = 1.0;
|
||||
else if (v < 0.0) v = 0.0;
|
||||
if (v > 1.0) {
|
||||
v = 1.0;
|
||||
} else if (v < 0.0) {
|
||||
v = 0.0;
|
||||
}
|
||||
|
||||
this.value = v;
|
||||
|
||||
@@ -533,7 +568,9 @@
|
||||
|
||||
WidgetProgress.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v != undefined) this.properties["value"] = v;
|
||||
if (v != undefined) {
|
||||
this.properties["value"] = v;
|
||||
}
|
||||
};
|
||||
|
||||
WidgetProgress.prototype.onDrawForeground = function(ctx) {
|
||||
@@ -582,7 +619,9 @@
|
||||
ctx.shadowOffsetX = 0;
|
||||
ctx.shadowOffsetY = 0;
|
||||
ctx.shadowBlur = this.properties["glowSize"];
|
||||
} else ctx.shadowColor = "transparent";
|
||||
} else {
|
||||
ctx.shadowColor = "transparent";
|
||||
}
|
||||
|
||||
var fontsize = this.properties["fontsize"];
|
||||
|
||||
@@ -593,12 +632,13 @@
|
||||
|
||||
if (typeof this.str == "string") {
|
||||
var lines = this.str.split("\\n");
|
||||
for (var i in lines)
|
||||
for (var i in lines) {
|
||||
ctx.fillText(
|
||||
lines[i],
|
||||
this.properties["align"] == "left" ? 15 : this.size[0] - 15,
|
||||
fontsize * -0.15 + fontsize * (parseInt(i) + 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.shadowColor = "transparent";
|
||||
@@ -608,12 +648,16 @@
|
||||
|
||||
WidgetText.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v != null) this.properties["value"] = v;
|
||||
if (v != null) {
|
||||
this.properties["value"] = v;
|
||||
}
|
||||
//this.setDirtyCanvas(true);
|
||||
};
|
||||
|
||||
WidgetText.prototype.resize = function() {
|
||||
if (!this.last_ctx) return;
|
||||
if (!this.last_ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = this.str.split("\\n");
|
||||
this.last_ctx.font =
|
||||
@@ -621,7 +665,9 @@
|
||||
var max = 0;
|
||||
for (var i in lines) {
|
||||
var w = this.last_ctx.measureText(lines[i]).width;
|
||||
if (max < w) max = w;
|
||||
if (max < w) {
|
||||
max = w;
|
||||
}
|
||||
}
|
||||
this.size[0] = max + 20;
|
||||
this.size[1] = 4 + lines.length * this.properties["fontsize"];
|
||||
@@ -668,11 +714,17 @@
|
||||
};
|
||||
|
||||
WidgetPanel.prototype.onDrawForeground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.lineargradient == null) this.createGradient(ctx);
|
||||
if (this.lineargradient == null) {
|
||||
this.createGradient(ctx);
|
||||
}
|
||||
|
||||
if (!this.lineargradient) return;
|
||||
if (!this.lineargradient) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeStyle = this.properties["borderColor"];
|
||||
@@ -684,7 +736,9 @@
|
||||
ctx.shadowOffsetX = 0;
|
||||
ctx.shadowOffsetY = 0;
|
||||
ctx.shadowBlur = this.properties["shadowSize"];
|
||||
} else ctx.shadowColor = "transparent";
|
||||
} else {
|
||||
ctx.shadowColor = "transparent";
|
||||
}
|
||||
|
||||
ctx.roundRect(
|
||||
0,
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
Selector.desc = "selects an output";
|
||||
|
||||
Selector.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
ctx.fillStyle = "#AFB";
|
||||
var y = (this.selected + 1) * LiteGraph.NODE_SLOT_HEIGHT + 6;
|
||||
ctx.beginPath();
|
||||
@@ -28,10 +30,14 @@
|
||||
|
||||
Selector.prototype.onExecute = function() {
|
||||
var sel = this.getInputData(0);
|
||||
if (sel == null) sel = 0;
|
||||
if (sel == null) {
|
||||
sel = 0;
|
||||
}
|
||||
this.selected = sel = Math.round(sel) % (this.inputs.length - 1);
|
||||
var v = this.getInputData(sel + 1);
|
||||
if (v !== undefined) this.setOutputData(0, v);
|
||||
if (v !== undefined) {
|
||||
this.setOutputData(0, v);
|
||||
}
|
||||
};
|
||||
|
||||
Selector.prototype.onGetInputs = function() {
|
||||
@@ -68,7 +74,9 @@
|
||||
this.current_sequence = seq;
|
||||
}
|
||||
var index = this.getInputData(0);
|
||||
if (index == null) index = 0;
|
||||
if (index == null) {
|
||||
index = 0;
|
||||
}
|
||||
this.index = index = Math.round(index) % this.values.length;
|
||||
|
||||
this.setOutputData(0, this.values[index]);
|
||||
|
||||
@@ -12,12 +12,16 @@
|
||||
|
||||
Converter.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.outputs)
|
||||
if (this.outputs) {
|
||||
for (var i = 0; i < this.outputs.length; i++) {
|
||||
var output = this.outputs[i];
|
||||
if (!output.links || !output.links.length) continue;
|
||||
if (!output.links || !output.links.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var result = null;
|
||||
switch (output.name) {
|
||||
@@ -47,13 +51,17 @@
|
||||
var j = 0;
|
||||
j < v.length && j < result.length;
|
||||
j++
|
||||
)
|
||||
) {
|
||||
result[j] = v[j];
|
||||
} else result[0] = parseFloat(v);
|
||||
}
|
||||
} else {
|
||||
result[0] = parseFloat(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.setOutputData(i, result);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Converter.prototype.onGetOutputs = function() {
|
||||
@@ -116,21 +124,28 @@
|
||||
MathRange.desc = "Convert a number from one range to another";
|
||||
|
||||
MathRange.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return (this._last_v || 0).toFixed(2);
|
||||
if (this.flags.collapsed) {
|
||||
return (this._last_v || 0).toFixed(2);
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
MathRange.prototype.onExecute = function() {
|
||||
if (this.inputs)
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; i++) {
|
||||
var input = this.inputs[i];
|
||||
var v = this.getInputData(i);
|
||||
if (v === undefined) continue;
|
||||
if (v === undefined) {
|
||||
continue;
|
||||
}
|
||||
this.properties[input.name] = v;
|
||||
}
|
||||
}
|
||||
|
||||
var v = this.properties["in"];
|
||||
if (v === undefined || v === null || v.constructor !== Number) v = 0;
|
||||
if (v === undefined || v === null || v.constructor !== Number) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
var in_min = this.properties.in_min;
|
||||
var in_max = this.properties.in_max;
|
||||
@@ -144,8 +159,11 @@
|
||||
|
||||
MathRange.prototype.onDrawBackground = function(ctx) {
|
||||
//show the current value
|
||||
if (this._last_v) this.outputs[0].label = this._last_v.toFixed(3);
|
||||
else this.outputs[0].label = "?";
|
||||
if (this._last_v) {
|
||||
this.outputs[0].label = this._last_v.toFixed(3);
|
||||
} else {
|
||||
this.outputs[0].label = "?";
|
||||
}
|
||||
};
|
||||
|
||||
MathRange.prototype.onGetInputs = function() {
|
||||
@@ -170,13 +188,16 @@
|
||||
MathRand.desc = "Random number";
|
||||
|
||||
MathRand.prototype.onExecute = function() {
|
||||
if (this.inputs)
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; i++) {
|
||||
var input = this.inputs[i];
|
||||
var v = this.getInputData(i);
|
||||
if (v === undefined) continue;
|
||||
if (v === undefined) {
|
||||
continue;
|
||||
}
|
||||
this.properties[input.name] = v;
|
||||
}
|
||||
}
|
||||
|
||||
var min = this.properties.min;
|
||||
var max = this.properties.max;
|
||||
@@ -212,16 +233,21 @@
|
||||
MathNoise.getValue = function(f, smooth) {
|
||||
if (!MathNoise.data) {
|
||||
MathNoise.data = new Float32Array(1024);
|
||||
for (var i = 0; i < MathNoise.data.length; ++i)
|
||||
for (var i = 0; i < MathNoise.data.length; ++i) {
|
||||
MathNoise.data[i] = Math.random();
|
||||
}
|
||||
}
|
||||
f = f % 1024;
|
||||
if (f < 0) f += 1024;
|
||||
if (f < 0) {
|
||||
f += 1024;
|
||||
}
|
||||
var f_min = Math.floor(f);
|
||||
var f = f - f_min;
|
||||
var r1 = MathNoise.data[f_min];
|
||||
var r2 = MathNoise.data[f_min == 1023 ? 0 : f_min + 1];
|
||||
if (smooth) f = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
||||
if (smooth) {
|
||||
f = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
||||
}
|
||||
return r1 * (1 - f) + r2 * f;
|
||||
};
|
||||
|
||||
@@ -274,7 +300,9 @@
|
||||
this.properties.min_time;
|
||||
this._blink_time = this.properties.duration;
|
||||
this.boxcolor = "#FFF";
|
||||
} else this.boxcolor = "#000";
|
||||
} else {
|
||||
this.boxcolor = "#000";
|
||||
}
|
||||
this.setOutputData(0, v);
|
||||
};
|
||||
|
||||
@@ -295,7 +323,9 @@
|
||||
|
||||
MathClamp.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
v = Math.max(this.properties.min, v);
|
||||
v = Math.min(this.properties.max, v);
|
||||
this.setOutputData(0, v);
|
||||
@@ -303,13 +333,14 @@
|
||||
|
||||
MathClamp.prototype.getCode = function(lang) {
|
||||
var code = "";
|
||||
if (this.isInputConnected(0))
|
||||
if (this.isInputConnected(0)) {
|
||||
code +=
|
||||
"clamp({{0}}," +
|
||||
this.properties.min +
|
||||
"," +
|
||||
this.properties.max +
|
||||
")";
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
@@ -329,14 +360,20 @@
|
||||
|
||||
MathLerp.prototype.onExecute = function() {
|
||||
var v1 = this.getInputData(0);
|
||||
if (v1 == null) v1 = 0;
|
||||
if (v1 == null) {
|
||||
v1 = 0;
|
||||
}
|
||||
var v2 = this.getInputData(1);
|
||||
if (v2 == null) v2 = 0;
|
||||
if (v2 == null) {
|
||||
v2 = 0;
|
||||
}
|
||||
|
||||
var f = this.properties.f;
|
||||
|
||||
var _f = this.getInputData(2);
|
||||
if (_f !== undefined) f = _f;
|
||||
if (_f !== undefined) {
|
||||
f = _f;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v1 * (1 - f) + v2 * f);
|
||||
};
|
||||
@@ -359,7 +396,9 @@
|
||||
|
||||
MathAbs.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
this.setOutputData(0, Math.abs(v));
|
||||
};
|
||||
|
||||
@@ -377,7 +416,9 @@
|
||||
|
||||
MathFloor.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
this.setOutputData(0, Math.floor(v));
|
||||
};
|
||||
|
||||
@@ -395,7 +436,9 @@
|
||||
|
||||
MathFrac.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
this.setOutputData(0, v % 1);
|
||||
};
|
||||
|
||||
@@ -414,7 +457,9 @@
|
||||
|
||||
MathSmoothStep.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v === undefined) return;
|
||||
if (v === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
var edge0 = this.properties.A;
|
||||
var edge1 = this.properties.B;
|
||||
@@ -442,8 +487,9 @@
|
||||
|
||||
MathScale.prototype.onExecute = function() {
|
||||
var value = this.getInputData(0);
|
||||
if (value != null)
|
||||
if (value != null) {
|
||||
this.setOutputData(0, value * this.properties.factor);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math/scale", MathScale);
|
||||
@@ -463,28 +509,39 @@
|
||||
|
||||
MathAverageFilter.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) v = 0;
|
||||
if (v == null) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
var num_samples = this._values.length;
|
||||
|
||||
this._values[this._current % num_samples] = v;
|
||||
this._current += 1;
|
||||
if (this._current > num_samples) this._current = 0;
|
||||
if (this._current > num_samples) {
|
||||
this._current = 0;
|
||||
}
|
||||
|
||||
var avr = 0;
|
||||
for (var i = 0; i < num_samples; ++i) avr += this._values[i];
|
||||
for (var i = 0; i < num_samples; ++i) {
|
||||
avr += this._values[i];
|
||||
}
|
||||
|
||||
this.setOutputData(0, avr / num_samples);
|
||||
};
|
||||
|
||||
MathAverageFilter.prototype.onPropertyChanged = function(name, value) {
|
||||
if (value < 1) value = 1;
|
||||
if (value < 1) {
|
||||
value = 1;
|
||||
}
|
||||
this.properties.samples = Math.round(value);
|
||||
var old = this._values;
|
||||
|
||||
this._values = new Float32Array(this.properties.samples);
|
||||
if (old.length <= this._values.length) this._values.set(old);
|
||||
else this._values.set(old.subarray(0, this._values.length));
|
||||
if (old.length <= this._values.length) {
|
||||
this._values.set(old);
|
||||
} else {
|
||||
this._values.set(old.subarray(0, this._values.length));
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math/average", MathAverageFilter);
|
||||
@@ -503,10 +560,15 @@
|
||||
|
||||
MathTendTo.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) v = 0;
|
||||
if (v == null) {
|
||||
v = 0;
|
||||
}
|
||||
var f = this.properties.factor;
|
||||
if (this._value == null) this._value = v;
|
||||
else this._value = this._value * (1 - f) + v * f;
|
||||
if (this._value == null) {
|
||||
this._value = v;
|
||||
} else {
|
||||
this._value = this._value * (1 - f) + v * f;
|
||||
}
|
||||
this.setOutputData(0, this._value);
|
||||
};
|
||||
|
||||
@@ -538,18 +600,26 @@
|
||||
};
|
||||
|
||||
MathOperation.prototype.setValue = function(v) {
|
||||
if (typeof v == "string") v = parseFloat(v);
|
||||
if (typeof v == "string") {
|
||||
v = parseFloat(v);
|
||||
}
|
||||
this.properties["value"] = v;
|
||||
};
|
||||
|
||||
MathOperation.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
var B = this.getInputData(1);
|
||||
if (A != null) this.properties["A"] = A;
|
||||
else A = this.properties["A"];
|
||||
if (A != null) {
|
||||
this.properties["A"] = A;
|
||||
} else {
|
||||
A = this.properties["A"];
|
||||
}
|
||||
|
||||
if (B != null) this.properties["B"] = B;
|
||||
else B = this.properties["B"];
|
||||
if (B != null) {
|
||||
this.properties["B"] = B;
|
||||
} else {
|
||||
B = this.properties["B"];
|
||||
}
|
||||
|
||||
var result = 0;
|
||||
switch (this.properties.OP) {
|
||||
@@ -580,7 +650,9 @@
|
||||
};
|
||||
|
||||
MathOperation.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.font = "40px Arial";
|
||||
ctx.fillStyle = "#666";
|
||||
@@ -611,15 +683,23 @@
|
||||
MathCompare.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
var B = this.getInputData(1);
|
||||
if (A !== undefined) this.properties["A"] = A;
|
||||
else A = this.properties["A"];
|
||||
if (A !== undefined) {
|
||||
this.properties["A"] = A;
|
||||
} else {
|
||||
A = this.properties["A"];
|
||||
}
|
||||
|
||||
if (B !== undefined) this.properties["B"] = B;
|
||||
else B = this.properties["B"];
|
||||
if (B !== undefined) {
|
||||
this.properties["B"] = B;
|
||||
} else {
|
||||
B = this.properties["B"];
|
||||
}
|
||||
|
||||
for (var i = 0, l = this.outputs.length; i < l; ++i) {
|
||||
var output = this.outputs[i];
|
||||
if (!output.links || !output.links.length) continue;
|
||||
if (!output.links || !output.links.length) {
|
||||
continue;
|
||||
}
|
||||
var value;
|
||||
switch (output.name) {
|
||||
case "A==B":
|
||||
@@ -706,12 +786,18 @@
|
||||
|
||||
MathCondition.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A === undefined) A = this.properties.A;
|
||||
else this.properties.A = A;
|
||||
if (A === undefined) {
|
||||
A = this.properties.A;
|
||||
} else {
|
||||
this.properties.A = A;
|
||||
}
|
||||
|
||||
var B = this.getInputData(1);
|
||||
if (B === undefined) B = this.properties.B;
|
||||
else this.properties.B = B;
|
||||
if (B === undefined) {
|
||||
B = this.properties.B;
|
||||
} else {
|
||||
this.properties.B = B;
|
||||
}
|
||||
|
||||
var result = true;
|
||||
switch (this.properties.OP) {
|
||||
@@ -751,11 +837,16 @@
|
||||
MathAccumulate.desc = "Increments a value every time";
|
||||
|
||||
MathAccumulate.prototype.onExecute = function() {
|
||||
if (this.properties.value === null) this.properties.value = 0;
|
||||
if (this.properties.value === null) {
|
||||
this.properties.value = 0;
|
||||
}
|
||||
|
||||
var inc = this.getInputData(0);
|
||||
if (inc !== null) this.properties.value += inc;
|
||||
else this.properties.value += this.properties.increment;
|
||||
if (inc !== null) {
|
||||
this.properties.value += inc;
|
||||
} else {
|
||||
this.properties.value += this.properties.increment;
|
||||
}
|
||||
this.setOutputData(0, this.properties.value);
|
||||
};
|
||||
|
||||
@@ -777,13 +868,19 @@
|
||||
|
||||
MathTrigonometry.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) v = 0;
|
||||
if (v == null) {
|
||||
v = 0;
|
||||
}
|
||||
var amplitude = this.properties["amplitude"];
|
||||
var slot = this.findInputSlot("amplitude");
|
||||
if (slot != -1) amplitude = this.getInputData(slot);
|
||||
if (slot != -1) {
|
||||
amplitude = this.getInputData(slot);
|
||||
}
|
||||
var offset = this.properties["offset"];
|
||||
slot = this.findInputSlot("offset");
|
||||
if (slot != -1) offset = this.getInputData(slot);
|
||||
if (slot != -1) {
|
||||
offset = this.getInputData(slot);
|
||||
}
|
||||
|
||||
for (var i = 0, l = this.outputs.length; i < l; ++i) {
|
||||
var output = this.outputs[i];
|
||||
@@ -867,19 +964,29 @@
|
||||
MathFormula.size = [160, 100];
|
||||
|
||||
MathAverageFilter.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "formula") this.code_widget.value = value;
|
||||
if (name == "formula") {
|
||||
this.code_widget.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
MathFormula.prototype.onExecute = function() {
|
||||
if (!LiteGraph.allow_scripts) return;
|
||||
if (!LiteGraph.allow_scripts) {
|
||||
return;
|
||||
}
|
||||
|
||||
var x = this.getInputData(0);
|
||||
var y = this.getInputData(1);
|
||||
if (x != null) this.properties["x"] = x;
|
||||
else x = this.properties["x"];
|
||||
if (x != null) {
|
||||
this.properties["x"] = x;
|
||||
} else {
|
||||
x = this.properties["x"];
|
||||
}
|
||||
|
||||
if (y != null) this.properties["y"] = y;
|
||||
else y = this.properties["y"];
|
||||
if (y != null) {
|
||||
this.properties["y"] = y;
|
||||
} else {
|
||||
y = this.properties["y"];
|
||||
}
|
||||
|
||||
var f = this.properties["formula"];
|
||||
|
||||
@@ -908,7 +1015,9 @@
|
||||
|
||||
MathFormula.prototype.onDrawBackground = function() {
|
||||
var f = this.properties["formula"];
|
||||
if (this.outputs && this.outputs.length) this.outputs[0].label = f;
|
||||
if (this.outputs && this.outputs.length) {
|
||||
this.outputs[0].label = f;
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math/formula", MathFormula);
|
||||
@@ -924,7 +1033,9 @@
|
||||
|
||||
Math3DVec2ToXYZ.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -944,9 +1055,13 @@
|
||||
|
||||
Math3DXYToVec2.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -969,7 +1084,9 @@
|
||||
|
||||
Math3DVec3ToXYZ.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -990,11 +1107,17 @@
|
||||
|
||||
Math3DXYZToVec3.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
var z = this.getInputData(2);
|
||||
if (z == null) z = this.properties.z;
|
||||
if (z == null) {
|
||||
z = this.properties.z;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -1019,7 +1142,9 @@
|
||||
|
||||
Math3DVec4ToXYZW.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -1046,13 +1171,21 @@
|
||||
|
||||
Math3DXYZWToVec4.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
var z = this.getInputData(2);
|
||||
if (z == null) z = this.properties.z;
|
||||
if (z == null) {
|
||||
z = this.properties.z;
|
||||
}
|
||||
var w = this.getInputData(3);
|
||||
if (w == null) w = this.properties.w;
|
||||
if (w == null) {
|
||||
w = this.properties.w;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -1099,9 +1232,13 @@
|
||||
|
||||
Math3DRotation.prototype.onExecute = function() {
|
||||
var angle = this.getInputData(0);
|
||||
if (angle == null) angle = this.properties.angle;
|
||||
if (angle == null) {
|
||||
angle = this.properties.angle;
|
||||
}
|
||||
var axis = this.getInputData(1);
|
||||
if (axis == null) axis = this.properties.axis;
|
||||
if (axis == null) {
|
||||
axis = this.properties.axis;
|
||||
}
|
||||
|
||||
var R = quat.setAxisAngle(this._value, axis, angle * 0.0174532925);
|
||||
this.setOutputData(0, R);
|
||||
@@ -1121,14 +1258,18 @@
|
||||
|
||||
Math3DRotateVec3.prototype.onExecute = function() {
|
||||
var vec = this.getInputData(0);
|
||||
if (vec == null) vec = this.properties.vec;
|
||||
if (vec == null) {
|
||||
vec = this.properties.vec;
|
||||
}
|
||||
var quat = this.getInputData(1);
|
||||
if (quat == null) this.setOutputData(vec);
|
||||
else
|
||||
if (quat == null) {
|
||||
this.setOutputData(vec);
|
||||
} else {
|
||||
this.setOutputData(
|
||||
0,
|
||||
vec3.transformQuat(vec3.create(), vec, quat)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math3d/rotate_vec3", Math3DRotateVec3);
|
||||
@@ -1145,9 +1286,13 @@
|
||||
|
||||
Math3DMultQuat.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A == null) return;
|
||||
if (A == null) {
|
||||
return;
|
||||
}
|
||||
var B = this.getInputData(1);
|
||||
if (B == null) return;
|
||||
if (B == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var R = quat.multiply(this._value, A, B);
|
||||
this.setOutputData(0, R);
|
||||
@@ -1172,11 +1317,17 @@
|
||||
|
||||
Math3DQuatSlerp.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A == null) return;
|
||||
if (A == null) {
|
||||
return;
|
||||
}
|
||||
var B = this.getInputData(1);
|
||||
if (B == null) return;
|
||||
if (B == null) {
|
||||
return;
|
||||
}
|
||||
var factor = this.properties.factor;
|
||||
if (this.getInputData(2) != null) factor = this.getInputData(2);
|
||||
if (this.getInputData(2) != null) {
|
||||
factor = this.getInputData(2);
|
||||
}
|
||||
|
||||
var R = quat.slerp(this._value, A, B, factor);
|
||||
this.setOutputData(0, R);
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
|
||||
Math3DVec2ToXYZ.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -32,9 +34,13 @@
|
||||
|
||||
Math3DXYToVec2.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -57,7 +63,9 @@
|
||||
|
||||
Math3DVec3ToXYZ.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -78,11 +86,17 @@
|
||||
|
||||
Math3DXYZToVec3.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
var z = this.getInputData(2);
|
||||
if (z == null) z = this.properties.z;
|
||||
if (z == null) {
|
||||
z = this.properties.z;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -107,7 +121,9 @@
|
||||
|
||||
Math3DVec4ToXYZW.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -134,13 +150,21 @@
|
||||
|
||||
Math3DXYZWToVec4.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
var z = this.getInputData(2);
|
||||
if (z == null) z = this.properties.z;
|
||||
if (z == null) {
|
||||
z = this.properties.z;
|
||||
}
|
||||
var w = this.getInputData(3);
|
||||
if (w == null) w = this.properties.w;
|
||||
if (w == null) {
|
||||
w = this.properties.w;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -166,9 +190,13 @@
|
||||
|
||||
Math3DVec3Scale.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
var f = this.getInputData(1);
|
||||
if (f == null) f = this.properties.f;
|
||||
if (f == null) {
|
||||
f = this.properties.f;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = v[0] * f;
|
||||
@@ -189,7 +217,9 @@
|
||||
|
||||
Math3DVec3Length.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
var dist = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
||||
this.setOutputData(0, dist);
|
||||
};
|
||||
@@ -207,7 +237,9 @@
|
||||
|
||||
Math3DVec3Normalize.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
var dist = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
||||
var data = this._data;
|
||||
data[0] = v[0] / dist;
|
||||
@@ -233,9 +265,13 @@
|
||||
|
||||
Math3DVec3Lerp.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A == null) return;
|
||||
if (A == null) {
|
||||
return;
|
||||
}
|
||||
var B = this.getInputData(1);
|
||||
if (B == null) return;
|
||||
if (B == null) {
|
||||
return;
|
||||
}
|
||||
var f = this.getInputOrProperty("f");
|
||||
|
||||
var data = this._data;
|
||||
@@ -259,9 +295,13 @@
|
||||
|
||||
Math3DVec3Dot.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A == null) return;
|
||||
if (A == null) {
|
||||
return;
|
||||
}
|
||||
var B = this.getInputData(1);
|
||||
if (B == null) return;
|
||||
if (B == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2];
|
||||
this.setOutputData(0, dot);
|
||||
@@ -285,8 +325,9 @@
|
||||
this._value[1] = this.getInputOrProperty("y");
|
||||
this._value[2] = this.getInputOrProperty("z");
|
||||
this._value[3] = this.getInputOrProperty("w");
|
||||
if (this.properties.normalize)
|
||||
if (this.properties.normalize) {
|
||||
quat.normalize(this._value, this._value);
|
||||
}
|
||||
this.setOutputData(0, this._value);
|
||||
};
|
||||
|
||||
@@ -314,9 +355,13 @@
|
||||
|
||||
Math3DRotation.prototype.onExecute = function() {
|
||||
var angle = this.getInputData(0);
|
||||
if (angle == null) angle = this.properties.angle;
|
||||
if (angle == null) {
|
||||
angle = this.properties.angle;
|
||||
}
|
||||
var axis = this.getInputData(1);
|
||||
if (axis == null) axis = this.properties.axis;
|
||||
if (axis == null) {
|
||||
axis = this.properties.axis;
|
||||
}
|
||||
|
||||
var R = quat.setAxisAngle(this._value, axis, angle * 0.0174532925);
|
||||
this.setOutputData(0, R);
|
||||
@@ -336,14 +381,18 @@
|
||||
|
||||
Math3DRotateVec3.prototype.onExecute = function() {
|
||||
var vec = this.getInputData(0);
|
||||
if (vec == null) vec = this.properties.vec;
|
||||
if (vec == null) {
|
||||
vec = this.properties.vec;
|
||||
}
|
||||
var quat = this.getInputData(1);
|
||||
if (quat == null) this.setOutputData(vec);
|
||||
else
|
||||
if (quat == null) {
|
||||
this.setOutputData(vec);
|
||||
} else {
|
||||
this.setOutputData(
|
||||
0,
|
||||
vec3.transformQuat(vec3.create(), vec, quat)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math3d/rotate_vec3", Math3DRotateVec3);
|
||||
@@ -360,9 +409,13 @@
|
||||
|
||||
Math3DMultQuat.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A == null) return;
|
||||
if (A == null) {
|
||||
return;
|
||||
}
|
||||
var B = this.getInputData(1);
|
||||
if (B == null) return;
|
||||
if (B == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var R = quat.multiply(this._value, A, B);
|
||||
this.setOutputData(0, R);
|
||||
@@ -387,11 +440,17 @@
|
||||
|
||||
Math3DQuatSlerp.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A == null) return;
|
||||
if (A == null) {
|
||||
return;
|
||||
}
|
||||
var B = this.getInputData(1);
|
||||
if (B == null) return;
|
||||
if (B == null) {
|
||||
return;
|
||||
}
|
||||
var factor = this.properties.factor;
|
||||
if (this.getInputData(2) != null) factor = this.getInputData(2);
|
||||
if (this.getInputData(2) != null) {
|
||||
factor = this.getInputData(2);
|
||||
}
|
||||
|
||||
var R = quat.slerp(this._value, A, B, factor);
|
||||
this.setOutputData(0, R);
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
this.cmd = 0;
|
||||
this.data = new Uint32Array(3);
|
||||
|
||||
if (data) this.setup(data);
|
||||
if (data) {
|
||||
this.setup(data);
|
||||
}
|
||||
}
|
||||
|
||||
LiteGraph.MIDIEvent = MIDIEvent;
|
||||
@@ -18,7 +20,9 @@
|
||||
|
||||
MIDIEvent.prototype.setup = function(data) {
|
||||
var raw_data = data;
|
||||
if (data.constructor === Object) raw_data = data.data;
|
||||
if (data.constructor === Object) {
|
||||
raw_data = data.data;
|
||||
}
|
||||
|
||||
this.data.set(raw_data);
|
||||
|
||||
@@ -27,11 +31,15 @@
|
||||
|
||||
var midiCommand = midiStatus & 0xf0;
|
||||
|
||||
if (midiStatus >= 0xf0) this.cmd = midiStatus;
|
||||
else this.cmd = midiCommand;
|
||||
if (midiStatus >= 0xf0) {
|
||||
this.cmd = midiStatus;
|
||||
} else {
|
||||
this.cmd = midiCommand;
|
||||
}
|
||||
|
||||
if (this.cmd == MIDIEvent.NOTEON && this.velocity == 0)
|
||||
if (this.cmd == MIDIEvent.NOTEON && this.velocity == 0) {
|
||||
this.cmd = MIDIEvent.NOTEOFF;
|
||||
}
|
||||
|
||||
this.cmd_str = MIDIEvent.commands[this.cmd] || "";
|
||||
|
||||
@@ -45,7 +53,9 @@
|
||||
|
||||
Object.defineProperty(MIDIEvent.prototype, "velocity", {
|
||||
get: function() {
|
||||
if (this.cmd == MIDIEvent.NOTEON) return this.data[2];
|
||||
if (this.cmd == MIDIEvent.NOTEON) {
|
||||
return this.data[2];
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
set: function(v) {
|
||||
@@ -85,7 +95,9 @@
|
||||
|
||||
Object.defineProperty(MIDIEvent.prototype, "note", {
|
||||
get: function() {
|
||||
if (this.cmd != MIDIEvent.NOTEON) return -1;
|
||||
if (this.cmd != MIDIEvent.NOTEON) {
|
||||
return -1;
|
||||
}
|
||||
return MIDIEvent.toNoteString(this.data[1], true);
|
||||
},
|
||||
set: function(v) {
|
||||
@@ -96,7 +108,9 @@
|
||||
|
||||
Object.defineProperty(MIDIEvent.prototype, "octave", {
|
||||
get: function() {
|
||||
if (this.cmd != MIDIEvent.NOTEON) return -1;
|
||||
if (this.cmd != MIDIEvent.NOTEON) {
|
||||
return -1;
|
||||
}
|
||||
var octave = this.data[1] - 24;
|
||||
return Math.floor(octave / 12 + 1);
|
||||
},
|
||||
@@ -137,9 +151,13 @@
|
||||
};
|
||||
|
||||
MIDIEvent.computeCommandFromString = function(str) {
|
||||
if (!str) return 0;
|
||||
if (!str) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (str && str.constructor === Number) return str;
|
||||
if (str && str.constructor === Number) {
|
||||
return str;
|
||||
}
|
||||
|
||||
str = str.toUpperCase();
|
||||
switch (str) {
|
||||
@@ -188,7 +206,9 @@
|
||||
var note = d - 21;
|
||||
var octave = Math.floor((d - 24) / 12 + 1);
|
||||
note = note % 12;
|
||||
if (note < 0) note = 12 + note;
|
||||
if (note < 0) {
|
||||
note = 12 + note;
|
||||
}
|
||||
return MIDIEvent.notes[note] + (skip_octave ? "" : octave);
|
||||
};
|
||||
|
||||
@@ -199,12 +219,18 @@
|
||||
|
||||
if (str[1] == "#") {
|
||||
note += "#";
|
||||
if (str.length > 2) octave = Number(str[2]);
|
||||
if (str.length > 2) {
|
||||
octave = Number(str[2]);
|
||||
}
|
||||
} else {
|
||||
if (str.length > 1) octave = Number(str[1]);
|
||||
if (str.length > 1) {
|
||||
octave = Number(str[1]);
|
||||
}
|
||||
}
|
||||
var pitch = MIDIEvent.note_to_index[note];
|
||||
if (pitch == null) return null;
|
||||
if (pitch == null) {
|
||||
return null;
|
||||
}
|
||||
return (octave - 1) * 12 + pitch + 21;
|
||||
};
|
||||
|
||||
@@ -236,8 +262,9 @@
|
||||
|
||||
MIDIEvent.prototype.toHexString = function() {
|
||||
var str = "";
|
||||
for (var i = 0; i < this.data.length; i++)
|
||||
for (var i = 0; i < this.data.length; i++) {
|
||||
str += this.data[i].toString(16) + " ";
|
||||
}
|
||||
};
|
||||
|
||||
MIDIEvent.prototype.toJSON = function() {
|
||||
@@ -297,15 +324,19 @@
|
||||
};
|
||||
|
||||
MIDIEvent.commands_reversed = {};
|
||||
for (var i in MIDIEvent.commands)
|
||||
for (var i in MIDIEvent.commands) {
|
||||
MIDIEvent.commands_reversed[MIDIEvent.commands[i]] = i;
|
||||
}
|
||||
|
||||
//MIDI wrapper
|
||||
function MIDIInterface(on_ready, on_error) {
|
||||
if (!navigator.requestMIDIAccess) {
|
||||
this.error = "not suppoorted";
|
||||
if (on_error) on_error("Not supported");
|
||||
else console.error("MIDI NOT SUPPORTED, enable by chrome://flags");
|
||||
if (on_error) {
|
||||
on_error("Not supported");
|
||||
} else {
|
||||
console.error("MIDI NOT SUPPORTED, enable by chrome://flags");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -331,7 +362,9 @@
|
||||
this.midi = midiAccess; // store in the global (in real usage, would probably keep in an object instance)
|
||||
this.updatePorts();
|
||||
|
||||
if (this.on_ready) this.on_ready(this);
|
||||
if (this.on_ready) {
|
||||
this.on_ready(this);
|
||||
}
|
||||
};
|
||||
|
||||
MIDIInterface.prototype.updatePorts = function() {
|
||||
@@ -419,16 +452,21 @@
|
||||
|
||||
MIDIInterface.prototype.openInputPort = function(port, callback) {
|
||||
var input_port = this.input_ports.get("input-" + port);
|
||||
if (!input_port) return false;
|
||||
if (!input_port) {
|
||||
return false;
|
||||
}
|
||||
MIDIInterface.input = this;
|
||||
var that = this;
|
||||
|
||||
input_port.onmidimessage = function(a) {
|
||||
var midi_event = new MIDIEvent(a.data);
|
||||
that.updateState(midi_event);
|
||||
if (callback) callback(a.data, midi_event);
|
||||
if (MIDIInterface.on_message)
|
||||
if (callback) {
|
||||
callback(a.data, midi_event);
|
||||
}
|
||||
if (MIDIInterface.on_message) {
|
||||
MIDIInterface.on_message(a.data, midi_event);
|
||||
}
|
||||
};
|
||||
console.log("port open: ", input_port);
|
||||
return true;
|
||||
@@ -451,16 +489,22 @@
|
||||
};
|
||||
|
||||
MIDIInterface.prototype.sendMIDI = function(port, midi_data) {
|
||||
if (!midi_data) return;
|
||||
if (!midi_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
var output_port = this.output_ports.get("output-" + port);
|
||||
if (!output_port) return;
|
||||
if (!output_port) {
|
||||
return;
|
||||
}
|
||||
|
||||
MIDIInterface.output = this;
|
||||
|
||||
if (midi_data.constructor === MIDIEvent)
|
||||
if (midi_data.constructor === MIDIEvent) {
|
||||
output_port.send(midi_data.data);
|
||||
else output_port.send(midi_data);
|
||||
} else {
|
||||
output_port.send(midi_data);
|
||||
}
|
||||
};
|
||||
|
||||
function LGMIDIIn() {
|
||||
@@ -476,7 +520,9 @@
|
||||
new MIDIInterface(function(midi) {
|
||||
//open
|
||||
that._midi = midi;
|
||||
if (that._waiting) that.onStart();
|
||||
if (that._waiting) {
|
||||
that.onStart();
|
||||
}
|
||||
that._waiting = false;
|
||||
});
|
||||
}
|
||||
@@ -488,7 +534,9 @@
|
||||
LGMIDIIn.color = MIDI_COLOR;
|
||||
|
||||
LGMIDIIn.prototype.getPropertyInfo = function(name) {
|
||||
if (!this._midi) return;
|
||||
if (!this._midi) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name == "port") {
|
||||
var values = {};
|
||||
@@ -502,12 +550,14 @@
|
||||
};
|
||||
|
||||
LGMIDIIn.prototype.onStart = function() {
|
||||
if (this._midi)
|
||||
if (this._midi) {
|
||||
this._midi.openInputPort(
|
||||
this.properties.port,
|
||||
this.onMIDIEvent.bind(this)
|
||||
);
|
||||
else this._waiting = true;
|
||||
} else {
|
||||
this._waiting = true;
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIIn.prototype.onMIDIEvent = function(data, midi_event) {
|
||||
@@ -515,16 +565,17 @@
|
||||
this.boxcolor = "#AFA";
|
||||
this._last_time = LiteGraph.getTime();
|
||||
this.trigger("on_midi", midi_event);
|
||||
if (midi_event.cmd == MIDIEvent.NOTEON)
|
||||
if (midi_event.cmd == MIDIEvent.NOTEON) {
|
||||
this.trigger("on_noteon", midi_event);
|
||||
else if (midi_event.cmd == MIDIEvent.NOTEOFF)
|
||||
} else if (midi_event.cmd == MIDIEvent.NOTEOFF) {
|
||||
this.trigger("on_noteoff", midi_event);
|
||||
else if (midi_event.cmd == MIDIEvent.CONTROLLERCHANGE)
|
||||
} else if (midi_event.cmd == MIDIEvent.CONTROLLERCHANGE) {
|
||||
this.trigger("on_cc", midi_event);
|
||||
else if (midi_event.cmd == MIDIEvent.PROGRAMCHANGE)
|
||||
} else if (midi_event.cmd == MIDIEvent.PROGRAMCHANGE) {
|
||||
this.trigger("on_pc", midi_event);
|
||||
else if (midi_event.cmd == MIDIEvent.PITCHBEND)
|
||||
} else if (midi_event.cmd == MIDIEvent.PITCHBEND) {
|
||||
this.trigger("on_pitchbend", midi_event);
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIIn.prototype.onDrawBackground = function(ctx) {
|
||||
@@ -600,7 +651,9 @@
|
||||
LGMIDIOut.color = MIDI_COLOR;
|
||||
|
||||
LGMIDIOut.prototype.getPropertyInfo = function(name) {
|
||||
if (!this._midi) return;
|
||||
if (!this._midi) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name == "port") {
|
||||
var values = {};
|
||||
@@ -615,8 +668,12 @@
|
||||
|
||||
LGMIDIOut.prototype.onAction = function(event, midi_event) {
|
||||
//console.log(midi_event);
|
||||
if (!this._midi) return;
|
||||
if (event == "send") this._midi.sendMIDI(this.port, midi_event);
|
||||
if (!this._midi) {
|
||||
return;
|
||||
}
|
||||
if (event == "send") {
|
||||
this._midi.sendMIDI(this.port, midi_event);
|
||||
}
|
||||
this.trigger("midi", midi_event);
|
||||
};
|
||||
|
||||
@@ -641,19 +698,27 @@
|
||||
LGMIDIShow.color = MIDI_COLOR;
|
||||
|
||||
LGMIDIShow.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return this._str;
|
||||
if (this.flags.collapsed) {
|
||||
return this._str;
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
LGMIDIShow.prototype.onAction = function(event, midi_event) {
|
||||
if (!midi_event) return;
|
||||
if (midi_event.constructor === MIDIEvent)
|
||||
if (!midi_event) {
|
||||
return;
|
||||
}
|
||||
if (midi_event.constructor === MIDIEvent) {
|
||||
this._str = midi_event.toString();
|
||||
else this._str = "???";
|
||||
} else {
|
||||
this._str = "???";
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIShow.prototype.onDrawForeground = function(ctx) {
|
||||
if (!this._str || this.flags.collapsed) return;
|
||||
if (!this._str || this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.font = "30px Arial";
|
||||
ctx.fillText(this._str, 10, this.size[1] * 0.8);
|
||||
@@ -701,10 +766,16 @@
|
||||
|
||||
LGMIDIFilter.prototype.getTitle = function() {
|
||||
var str = null;
|
||||
if (this.properties.cmd == -1) str = "Nothing";
|
||||
else str = MIDIEvent.commands_short[this.properties.cmd] || "Unknown";
|
||||
if (this.properties.cmd == -1) {
|
||||
str = "Nothing";
|
||||
} else {
|
||||
str = MIDIEvent.commands_short[this.properties.cmd] || "Unknown";
|
||||
}
|
||||
|
||||
if (this.properties.min_value != -1 && this.properties.max_value != -1)
|
||||
if (
|
||||
this.properties.min_value != -1 &&
|
||||
this.properties.max_value != -1
|
||||
) {
|
||||
str +=
|
||||
" " +
|
||||
(this.properties.min_value == this.properties.max_value
|
||||
@@ -712,6 +783,7 @@
|
||||
: this.properties.min_value +
|
||||
".." +
|
||||
this.properties.max_value);
|
||||
}
|
||||
|
||||
return "Filter: " + str;
|
||||
};
|
||||
@@ -719,13 +791,17 @@
|
||||
LGMIDIFilter.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "cmd") {
|
||||
var num = Number(value);
|
||||
if (isNaN(num)) num = MIDIEvent.commands[value] || 0;
|
||||
if (isNaN(num)) {
|
||||
num = MIDIEvent.commands[value] || 0;
|
||||
}
|
||||
this.properties.cmd = num;
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIFilter.prototype.onAction = function(event, midi_event) {
|
||||
if (!midi_event || midi_event.constructor !== MIDIEvent) return;
|
||||
if (!midi_event || midi_event.constructor !== MIDIEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._learning) {
|
||||
this._learning = false;
|
||||
@@ -738,23 +814,27 @@
|
||||
if (
|
||||
this.properties.channel != -1 &&
|
||||
midi_event.channel != this.properties.channel
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
this.properties.cmd != -1 &&
|
||||
midi_event.cmd != this.properties.cmd
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
this.properties.min_value != -1 &&
|
||||
midi_event.data[1] < this.properties.min_value
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
this.properties.max_value != -1 &&
|
||||
midi_event.data[1] > this.properties.max_value
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.trigger("on_midi", midi_event);
|
||||
@@ -788,17 +868,22 @@
|
||||
this.properties.cmd = midi_event.cmd;
|
||||
this.properties.value1 = midi_event.data[1];
|
||||
this.properties.value2 = midi_event.data[2];
|
||||
if (midi_event.cmd == MIDIEvent.NOTEON) this.gate = true;
|
||||
else if (midi_event.cmd == MIDIEvent.NOTEOFF) this.gate = false;
|
||||
if (midi_event.cmd == MIDIEvent.NOTEON) {
|
||||
this.gate = true;
|
||||
} else if (midi_event.cmd == MIDIEvent.NOTEOFF) {
|
||||
this.gate = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//send
|
||||
var midi_event = this.midi_event;
|
||||
midi_event.channel = this.properties.channel;
|
||||
if (this.properties.cmd && this.properties.cmd.constructor === String)
|
||||
if (this.properties.cmd && this.properties.cmd.constructor === String) {
|
||||
midi_event.setCommandFromString(this.properties.cmd);
|
||||
else midi_event.cmd = this.properties.cmd;
|
||||
} else {
|
||||
midi_event.cmd = this.properties.cmd;
|
||||
}
|
||||
midi_event.data[0] = midi_event.cmd | midi_event.channel;
|
||||
midi_event.data[1] = Number(this.properties.value1);
|
||||
midi_event.data[2] = Number(this.properties.value2);
|
||||
@@ -812,13 +897,16 @@
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
if (input.link == -1) continue;
|
||||
if (input.link == -1) {
|
||||
continue;
|
||||
}
|
||||
switch (input.name) {
|
||||
case "note":
|
||||
var v = this.getInputData(i);
|
||||
if (v != null) {
|
||||
if (v.constructor === String)
|
||||
if (v.constructor === String) {
|
||||
v = MIDIEvent.NoteStringToPitch(v);
|
||||
}
|
||||
this.properties.value1 = (v | 0) % 255;
|
||||
}
|
||||
break;
|
||||
@@ -876,14 +964,17 @@
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
if (v !== null) this.setOutputData(i, v);
|
||||
if (v !== null) {
|
||||
this.setOutputData(i, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIEvent.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "cmd")
|
||||
if (name == "cmd") {
|
||||
this.properties.cmd = MIDIEvent.computeCommandFromString(value);
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIEvent.prototype.onGetInputs = function() {
|
||||
@@ -923,9 +1014,10 @@
|
||||
|
||||
LGMIDICC.prototype.onExecute = function() {
|
||||
var props = this.properties;
|
||||
if (MIDIInterface.input)
|
||||
if (MIDIInterface.input) {
|
||||
this.properties.value =
|
||||
MIDIInterface.input.state.cc[this.properties.cc];
|
||||
}
|
||||
this.setOutputData(0, this.properties.value);
|
||||
};
|
||||
|
||||
@@ -957,24 +1049,31 @@
|
||||
var notes = scale.split(",");
|
||||
for (var i = 0; i < notes.length; ++i) {
|
||||
var n = notes[i];
|
||||
if ((n.length == 2 && n[1] != "#") || n.length > 2)
|
||||
if ((n.length == 2 && n[1] != "#") || n.length > 2) {
|
||||
notes[i] = -LiteGraph.MIDIEvent.NoteStringToPitch(n);
|
||||
else notes[i] = MIDIEvent.note_to_index[n] || 0;
|
||||
} else {
|
||||
notes[i] = MIDIEvent.note_to_index[n] || 0;
|
||||
}
|
||||
}
|
||||
return notes;
|
||||
};
|
||||
|
||||
LGMIDIGenerator.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "notes")
|
||||
if (name == "notes") {
|
||||
this.notes_pitches = LGMIDIGenerator.processScale(value);
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIGenerator.prototype.onExecute = function() {
|
||||
var octave = this.getInputData(2);
|
||||
if (octave != null) this.properties.octave = octave;
|
||||
if (octave != null) {
|
||||
this.properties.octave = octave;
|
||||
}
|
||||
|
||||
var scale = this.getInputData(1);
|
||||
if (scale) this.notes_pitches = LGMIDIGenerator.processScale(scale);
|
||||
if (scale) {
|
||||
this.notes_pitches = LGMIDIGenerator.processScale(scale);
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIGenerator.prototype.onAction = function(event, midi_event) {
|
||||
@@ -984,14 +1083,18 @@
|
||||
var range = this.notes_pitches.length;
|
||||
var index = 0;
|
||||
|
||||
if (this.properties.mode == "sequence")
|
||||
if (this.properties.mode == "sequence") {
|
||||
index = this.sequence_index = (this.sequence_index + 1) % range;
|
||||
else if (this.properties.mode == "random")
|
||||
} else if (this.properties.mode == "random") {
|
||||
index = Math.floor(Math.random() * range);
|
||||
}
|
||||
|
||||
var note = this.notes_pitches[index];
|
||||
if (note >= 0) pitch = note + (this.properties.octave - 1) * 12 + 33;
|
||||
else pitch = -note;
|
||||
if (note >= 0) {
|
||||
pitch = note + (this.properties.octave - 1) * 12 + 33;
|
||||
} else {
|
||||
pitch = -note;
|
||||
}
|
||||
|
||||
var midi_event = new MIDIEvent();
|
||||
midi_event.setup([MIDIEvent.NOTEON, pitch, 10]);
|
||||
@@ -1027,7 +1130,9 @@
|
||||
LGMIDITranspose.color = MIDI_COLOR;
|
||||
|
||||
LGMIDITranspose.prototype.onAction = function(event, midi_event) {
|
||||
if (!midi_event || midi_event.constructor !== MIDIEvent) return;
|
||||
if (!midi_event || midi_event.constructor !== MIDIEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
midi_event.data[0] == MIDIEvent.NOTEON ||
|
||||
@@ -1039,12 +1144,16 @@
|
||||
this.midi_event.data[1] + this.properties.amount
|
||||
);
|
||||
this.trigger("out", this.midi_event);
|
||||
} else this.trigger("out", midi_event);
|
||||
} else {
|
||||
this.trigger("out", midi_event);
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDITranspose.prototype.onExecute = function() {
|
||||
var amount = this.getInputData(1);
|
||||
if (amount != null) this.properties.amount = amount;
|
||||
if (amount != null) {
|
||||
this.properties.amount = amount;
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("midi/transpose", LGMIDITranspose);
|
||||
@@ -1067,14 +1176,17 @@
|
||||
LGMIDIQuantize.color = MIDI_COLOR;
|
||||
|
||||
LGMIDIQuantize.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "scale") this.processScale(value);
|
||||
if (name == "scale") {
|
||||
this.processScale(value);
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIQuantize.prototype.processScale = function(scale) {
|
||||
this._current_scale = scale;
|
||||
this.notes_pitches = LGMIDIGenerator.processScale(scale);
|
||||
for (var i = 0; i < 12; ++i)
|
||||
for (var i = 0; i < 12; ++i) {
|
||||
this.valid_notes[i] = this.notes_pitches.indexOf(i) != -1;
|
||||
}
|
||||
for (var i = 0; i < 12; ++i) {
|
||||
if (this.valid_notes[i]) {
|
||||
this.offset_notes[i] = 0;
|
||||
@@ -1094,7 +1206,9 @@
|
||||
};
|
||||
|
||||
LGMIDIQuantize.prototype.onAction = function(event, midi_event) {
|
||||
if (!midi_event || midi_event.constructor !== MIDIEvent) return;
|
||||
if (!midi_event || midi_event.constructor !== MIDIEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
midi_event.data[0] == MIDIEvent.NOTEON ||
|
||||
@@ -1107,13 +1221,16 @@
|
||||
var offset = this.offset_notes[index];
|
||||
this.midi_event.data[1] += offset;
|
||||
this.trigger("out", this.midi_event);
|
||||
} else this.trigger("out", midi_event);
|
||||
} else {
|
||||
this.trigger("out", midi_event);
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIQuantize.prototype.onExecute = function() {
|
||||
var scale = this.getInputData(1);
|
||||
if (scale != null && scale != this._current_scale)
|
||||
if (scale != null && scale != this._current_scale) {
|
||||
this.processScale(scale);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("midi/quantize", LGMIDIQuantize);
|
||||
@@ -1144,12 +1261,15 @@
|
||||
LGMIDIPlay.color = MIDI_COLOR;
|
||||
|
||||
LGMIDIPlay.prototype.onAction = function(event, midi_event) {
|
||||
if (!midi_event || midi_event.constructor !== MIDIEvent) return;
|
||||
if (!midi_event || midi_event.constructor !== MIDIEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.instrument && midi_event.data[0] == MIDIEvent.NOTEON) {
|
||||
var note = midi_event.note; //C#
|
||||
if (!note || note == "undefined" || note.constructor !== String)
|
||||
if (!note || note == "undefined" || note.constructor !== String) {
|
||||
return;
|
||||
}
|
||||
this.instrument.play(
|
||||
note,
|
||||
midi_event.octave,
|
||||
@@ -1162,10 +1282,14 @@
|
||||
|
||||
LGMIDIPlay.prototype.onExecute = function() {
|
||||
var volume = this.getInputData(1);
|
||||
if (volume != null) this.properties.volume = volume;
|
||||
if (volume != null) {
|
||||
this.properties.volume = volume;
|
||||
}
|
||||
|
||||
var duration = this.getInputData(2);
|
||||
if (duration != null) this.properties.duration = duration;
|
||||
if (duration != null) {
|
||||
this.properties.duration = duration;
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("midi/play", LGMIDIPlay);
|
||||
@@ -1203,7 +1327,9 @@
|
||||
];
|
||||
|
||||
LGMIDIKeys.prototype.onDrawForeground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
var num_keys = this.properties.num_octaves * 12;
|
||||
this.keys.length = num_keys;
|
||||
@@ -1216,14 +1342,19 @@
|
||||
var k = 0;
|
||||
k < 2;
|
||||
k++ //draw first whites (0) then blacks (1)
|
||||
)
|
||||
) {
|
||||
for (var i = 0; i < num_keys; ++i) {
|
||||
var key_info = LGMIDIKeys.keys[i % 12];
|
||||
if (key_info.t != k) continue;
|
||||
if (key_info.t != k) {
|
||||
continue;
|
||||
}
|
||||
var octave = Math.floor(i / 12);
|
||||
var x = octave * 7 * key_width + key_info.x * key_width;
|
||||
if (k == 0) ctx.fillStyle = this.keys[i] ? "#CCC" : "white";
|
||||
else ctx.fillStyle = this.keys[i] ? "#333" : "black";
|
||||
if (k == 0) {
|
||||
ctx.fillStyle = this.keys[i] ? "#CCC" : "white";
|
||||
} else {
|
||||
ctx.fillStyle = this.keys[i] ? "#333" : "black";
|
||||
}
|
||||
ctx.fillRect(
|
||||
x + 1,
|
||||
0,
|
||||
@@ -1231,6 +1362,7 @@
|
||||
key_height * key_info.h
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIKeys.prototype.getKeyIndex = function(pos) {
|
||||
@@ -1242,41 +1374,54 @@
|
||||
var k = 1;
|
||||
k >= 0;
|
||||
k-- //test blacks first (1) then whites (0)
|
||||
)
|
||||
) {
|
||||
for (var i = 0; i < this.keys.length; ++i) {
|
||||
var key_info = LGMIDIKeys.keys[i % 12];
|
||||
if (key_info.t != k) continue;
|
||||
if (key_info.t != k) {
|
||||
continue;
|
||||
}
|
||||
var octave = Math.floor(i / 12);
|
||||
var x = octave * 7 * key_width + key_info.x * key_width;
|
||||
var w = key_width * key_info.w;
|
||||
var h = key_height * key_info.h;
|
||||
if (pos[0] < x || pos[0] > x + w || pos[1] > h) continue;
|
||||
if (pos[0] < x || pos[0] > x + w || pos[1] > h) {
|
||||
continue;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
LGMIDIKeys.prototype.onAction = function(event, params) {
|
||||
if (event == "reset") {
|
||||
for (var i = 0; i < this.keys.length; ++i) this.keys[i] = false;
|
||||
for (var i = 0; i < this.keys.length; ++i) {
|
||||
this.keys[i] = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!params || params.constructor !== MIDIEvent) return;
|
||||
if (!params || params.constructor !== MIDIEvent) {
|
||||
return;
|
||||
}
|
||||
var midi_event = params;
|
||||
var start_note = (this.properties.start_octave - 1) * 12 + 29;
|
||||
var index = midi_event.data[1] - start_note;
|
||||
if (index >= 0 && index < this.keys.length) {
|
||||
if (midi_event.data[0] == MIDIEvent.NOTEON) this.keys[index] = true;
|
||||
else if (midi_event.data[0] == MIDIEvent.NOTEOFF)
|
||||
if (midi_event.data[0] == MIDIEvent.NOTEON) {
|
||||
this.keys[index] = true;
|
||||
} else if (midi_event.data[0] == MIDIEvent.NOTEOFF) {
|
||||
this.keys[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.trigger("note", midi_event);
|
||||
};
|
||||
|
||||
LGMIDIKeys.prototype.onMouseDown = function(e, pos) {
|
||||
if (pos[1] < 0) return;
|
||||
if (pos[1] < 0) {
|
||||
return;
|
||||
}
|
||||
var index = this.getKeyIndex(pos);
|
||||
this.keys[index] = true;
|
||||
this._last_key = index;
|
||||
@@ -1288,10 +1433,14 @@
|
||||
};
|
||||
|
||||
LGMIDIKeys.prototype.onMouseMove = function(e, pos) {
|
||||
if (pos[1] < 0 || this._last_key == -1) return;
|
||||
if (pos[1] < 0 || this._last_key == -1) {
|
||||
return;
|
||||
}
|
||||
this.setDirtyCanvas(true);
|
||||
var index = this.getKeyIndex(pos);
|
||||
if (this._last_key == index) return true;
|
||||
if (this._last_key == index) {
|
||||
return true;
|
||||
}
|
||||
this.keys[this._last_key] = false;
|
||||
var pitch =
|
||||
(this.properties.start_octave - 1) * 12 + 29 + this._last_key;
|
||||
@@ -1310,7 +1459,9 @@
|
||||
};
|
||||
|
||||
LGMIDIKeys.prototype.onMouseUp = function(e, pos) {
|
||||
if (pos[1] < 0) return;
|
||||
if (pos[1] < 0) {
|
||||
return;
|
||||
}
|
||||
var index = this.getKeyIndex(pos);
|
||||
this.keys[index] = false;
|
||||
this._last_key = -1;
|
||||
|
||||
@@ -22,20 +22,28 @@
|
||||
LGWebSocket.desc = "Send data through a websocket";
|
||||
|
||||
LGWebSocket.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "url") this.connectSocket();
|
||||
if (name == "url") {
|
||||
this.connectSocket();
|
||||
}
|
||||
};
|
||||
|
||||
LGWebSocket.prototype.onExecute = function() {
|
||||
if (!this._ws && this.properties.url) this.connectSocket();
|
||||
if (!this._ws && this.properties.url) {
|
||||
this.connectSocket();
|
||||
}
|
||||
|
||||
if (!this._ws || this._ws.readyState != WebSocket.OPEN) return;
|
||||
if (!this._ws || this._ws.readyState != WebSocket.OPEN) {
|
||||
return;
|
||||
}
|
||||
|
||||
var room = this.properties.room;
|
||||
var only_changes = this.properties.only_send_changes;
|
||||
|
||||
for (var i = 1; i < this.inputs.length; ++i) {
|
||||
var data = this.getInputData(i);
|
||||
if (data == null) continue;
|
||||
if (data == null) {
|
||||
continue;
|
||||
}
|
||||
var json;
|
||||
try {
|
||||
json = JSON.stringify({
|
||||
@@ -47,22 +55,29 @@
|
||||
} catch (err) {
|
||||
continue;
|
||||
}
|
||||
if (only_changes && this._last_sent_data[i] == json) continue;
|
||||
if (only_changes && this._last_sent_data[i] == json) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this._last_sent_data[i] = json;
|
||||
this._ws.send(json);
|
||||
}
|
||||
|
||||
for (var i = 1; i < this.outputs.length; ++i)
|
||||
for (var i = 1; i < this.outputs.length; ++i) {
|
||||
this.setOutputData(i, this._last_received_data[i]);
|
||||
}
|
||||
|
||||
if (this.boxcolor == "#AFA") this.boxcolor = "#6C6";
|
||||
if (this.boxcolor == "#AFA") {
|
||||
this.boxcolor = "#6C6";
|
||||
}
|
||||
};
|
||||
|
||||
LGWebSocket.prototype.connectSocket = function() {
|
||||
var that = this;
|
||||
var url = this.properties.url;
|
||||
if (url.substr(0, 2) != "ws") url = "ws://" + url;
|
||||
if (url.substr(0, 2) != "ws") {
|
||||
url = "ws://" + url;
|
||||
}
|
||||
this._ws = new WebSocket(url);
|
||||
this._ws.onopen = function() {
|
||||
console.log("ready");
|
||||
@@ -71,7 +86,9 @@
|
||||
this._ws.onmessage = function(e) {
|
||||
that.boxcolor = "#AFA";
|
||||
var data = JSON.parse(e.data);
|
||||
if (data.room && data.room != this.properties.room) return;
|
||||
if (data.room && data.room != this.properties.room) {
|
||||
return;
|
||||
}
|
||||
if (e.data.type == 1) {
|
||||
if (
|
||||
data.data.object_class &&
|
||||
@@ -84,8 +101,12 @@
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
} else that.triggerSlot(0, data.data);
|
||||
} else that._last_received_data[e.data.channel || 0] = data.data;
|
||||
} else {
|
||||
that.triggerSlot(0, data.data);
|
||||
}
|
||||
} else {
|
||||
that._last_received_data[e.data.channel || 0] = data.data;
|
||||
}
|
||||
};
|
||||
this._ws.onerror = function(e) {
|
||||
console.log("couldnt connect to websocket");
|
||||
@@ -98,12 +119,16 @@
|
||||
};
|
||||
|
||||
LGWebSocket.prototype.send = function(data) {
|
||||
if (!this._ws || this._ws.readyState != WebSocket.OPEN) return;
|
||||
if (!this._ws || this._ws.readyState != WebSocket.OPEN) {
|
||||
return;
|
||||
}
|
||||
this._ws.send(JSON.stringify({ type: 1, msg: data }));
|
||||
};
|
||||
|
||||
LGWebSocket.prototype.onAction = function(action, param) {
|
||||
if (!this._ws || this._ws.readyState != WebSocket.OPEN) return;
|
||||
if (!this._ws || this._ws.readyState != WebSocket.OPEN) {
|
||||
return;
|
||||
}
|
||||
this._ws.send({
|
||||
type: 1,
|
||||
room: this.properties.room,
|
||||
@@ -160,7 +185,9 @@
|
||||
LGSillyClient.desc = "Connects to SillyServer to broadcast messages";
|
||||
|
||||
LGSillyClient.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "room") this.room_widget.value = value;
|
||||
if (name == "room") {
|
||||
this.room_widget.value = value;
|
||||
}
|
||||
this.connectSocket();
|
||||
};
|
||||
|
||||
@@ -183,33 +210,40 @@
|
||||
};
|
||||
|
||||
LGSillyClient.prototype.onExecute = function() {
|
||||
if (!this._server || !this._server.is_connected) return;
|
||||
if (!this._server || !this._server.is_connected) {
|
||||
return;
|
||||
}
|
||||
|
||||
var only_send_changes = this.properties.only_send_changes;
|
||||
|
||||
for (var i = 1; i < this.inputs.length; ++i) {
|
||||
var data = this.getInputData(i);
|
||||
if (data != null) {
|
||||
if (only_send_changes && this._last_sent_data[i] == data)
|
||||
if (only_send_changes && this._last_sent_data[i] == data) {
|
||||
continue;
|
||||
}
|
||||
this._server.sendMessage({ type: 0, channel: i, data: data });
|
||||
this._last_sent_data[i] = data;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 1; i < this.outputs.length; ++i)
|
||||
for (var i = 1; i < this.outputs.length; ++i) {
|
||||
this.setOutputData(i, this._last_received_data[i]);
|
||||
}
|
||||
|
||||
if (this.boxcolor == "#AFA") this.boxcolor = "#6C6";
|
||||
if (this.boxcolor == "#AFA") {
|
||||
this.boxcolor = "#6C6";
|
||||
}
|
||||
};
|
||||
|
||||
LGSillyClient.prototype.connectSocket = function() {
|
||||
var that = this;
|
||||
if (typeof SillyClient == "undefined") {
|
||||
if (!this._error)
|
||||
if (!this._error) {
|
||||
console.error(
|
||||
"SillyClient node cannot be used, you must include SillyServer.js"
|
||||
);
|
||||
}
|
||||
this._error = true;
|
||||
return;
|
||||
}
|
||||
@@ -240,9 +274,13 @@
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
} else that.triggerSlot(0, data.data);
|
||||
} else {
|
||||
that.triggerSlot(0, data.data);
|
||||
}
|
||||
} //for FLOW slots
|
||||
else that._last_received_data[data.channel || 0] = data.data;
|
||||
else {
|
||||
that._last_received_data[data.channel || 0] = data.data;
|
||||
}
|
||||
that.boxcolor = "#AFA";
|
||||
};
|
||||
this._server.on_error = function(e) {
|
||||
@@ -267,12 +305,16 @@
|
||||
};
|
||||
|
||||
LGSillyClient.prototype.send = function(data) {
|
||||
if (!this._server || !this._server.is_connected) return;
|
||||
if (!this._server || !this._server.is_connected) {
|
||||
return;
|
||||
}
|
||||
this._server.sendMessage({ type: 1, data: data });
|
||||
};
|
||||
|
||||
LGSillyClient.prototype.onAction = function(action, param) {
|
||||
if (!this._server || !this._server.is_connected) return;
|
||||
if (!this._server || !this._server.is_connected) {
|
||||
return;
|
||||
}
|
||||
this._server.sendMessage({ type: 1, action: action, data: param });
|
||||
};
|
||||
|
||||
|
||||
@@ -20,8 +20,12 @@
|
||||
);
|
||||
|
||||
function concatenate(a, b) {
|
||||
if (a === undefined) return b;
|
||||
if (b === undefined) return a;
|
||||
if (a === undefined) {
|
||||
return b;
|
||||
}
|
||||
if (b === undefined) {
|
||||
return a;
|
||||
}
|
||||
return a + b;
|
||||
}
|
||||
|
||||
@@ -33,7 +37,9 @@
|
||||
);
|
||||
|
||||
function contains(a, b) {
|
||||
if (a === undefined || b === undefined) return false;
|
||||
if (a === undefined || b === undefined) {
|
||||
return false;
|
||||
}
|
||||
return a.indexOf(b) != -1;
|
||||
}
|
||||
|
||||
@@ -45,7 +51,9 @@
|
||||
);
|
||||
|
||||
function toUpperCase(a) {
|
||||
if (a != null && a.constructor === String) return a.toUpperCase();
|
||||
if (a != null && a.constructor === String) {
|
||||
return a.toUpperCase();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -57,7 +65,9 @@
|
||||
);
|
||||
|
||||
function split(a, b) {
|
||||
if (a != null && a.constructor === String) return a.split(b || " ");
|
||||
if (a != null && a.constructor === String) {
|
||||
return a.split(b || " ");
|
||||
}
|
||||
return [a];
|
||||
}
|
||||
|
||||
@@ -69,8 +79,9 @@
|
||||
);
|
||||
|
||||
function toFixed(a) {
|
||||
if (a != null && a.constructor === Number)
|
||||
if (a != null && a.constructor === Number) {
|
||||
return a.toFixed(this.properties.precision);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user