mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-27 09:45:13 +00:00
fix in widgets
This commit is contained in:
@@ -882,6 +882,24 @@
|
||||
this.properties.value1 = (v | 0) % 255;
|
||||
}
|
||||
break;
|
||||
case "cmd":
|
||||
var v = this.getInputData(i);
|
||||
if (v != null) {
|
||||
this.properties.cmd = v;
|
||||
}
|
||||
break;
|
||||
case "value1":
|
||||
var v = this.getInputData(i);
|
||||
if (v != null) {
|
||||
this.properties.value1 = Math.clamp(v|0,0,127);
|
||||
}
|
||||
break;
|
||||
case "value2":
|
||||
var v = this.getInputData(i);
|
||||
if (v != null) {
|
||||
this.properties.value2 = Math.clamp(v|0,0,127);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -950,7 +968,7 @@
|
||||
};
|
||||
|
||||
LGMIDIEvent.prototype.onGetInputs = function() {
|
||||
return [["note", "number"]];
|
||||
return [["cmd", "number"],["note", "number"],["value1", "number"],["value2", "number"]];
|
||||
};
|
||||
|
||||
LGMIDIEvent.prototype.onGetOutputs = function() {
|
||||
@@ -1207,6 +1225,119 @@
|
||||
|
||||
LiteGraph.registerNodeType("midi/quantize", LGMIDIQuantize);
|
||||
|
||||
function LGMIDIFromFile() {
|
||||
this.properties = {
|
||||
url: "",
|
||||
autoplay: true
|
||||
};
|
||||
|
||||
this.addInput("play", LiteGraph.ACTION);
|
||||
this.addInput("pause", LiteGraph.ACTION);
|
||||
this.addOutput("note", LiteGraph.EVENT);
|
||||
this._midi = null;
|
||||
this._current_time = 0;
|
||||
this._playing = false;
|
||||
|
||||
if (typeof MidiParser == "undefined") {
|
||||
console.error(
|
||||
"midi-parser.js not included, LGMidiPlay requires that library: https://raw.githubusercontent.com/colxi/midi-parser-js/master/src/main.js"
|
||||
);
|
||||
this.boxcolor = "red";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LGMIDIFromFile.title = "MIDI fromFile";
|
||||
LGMIDIFromFile.desc = "Plays a MIDI file";
|
||||
LGMIDIFromFile.color = MIDI_COLOR;
|
||||
|
||||
LGMIDIFromFile.prototype.onAction = function( name )
|
||||
{
|
||||
if(name == "play")
|
||||
this.play();
|
||||
else if(name == "pause")
|
||||
this._playing = !this._playing;
|
||||
}
|
||||
|
||||
LGMIDIFromFile.prototype.onPropertyChanged = function(name,value)
|
||||
{
|
||||
if(name == "url")
|
||||
this.loadMIDIFile(value);
|
||||
}
|
||||
|
||||
LGMIDIFromFile.prototype.onExecute = function() {
|
||||
if(!this._midi)
|
||||
return;
|
||||
|
||||
if(!this._playing)
|
||||
return;
|
||||
|
||||
this._current_time += this.graph.elapsed_time;
|
||||
var current_time = this._current_time * 100;
|
||||
|
||||
for(var i = 0; i < this._midi.tracks; ++i)
|
||||
{
|
||||
var track = this._midi.track[i];
|
||||
if(!track._last_pos)
|
||||
{
|
||||
track._last_pos = 0;
|
||||
track._time = 0;
|
||||
}
|
||||
|
||||
var elem = track.event[ track._last_pos ];
|
||||
if(elem && (track._time + elem.deltaTime) <= current_time )
|
||||
{
|
||||
track._last_pos++;
|
||||
track._time += elem.deltaTime;
|
||||
|
||||
if(elem.data)
|
||||
{
|
||||
var midi_cmd = elem.type << 4 + elem.channel;
|
||||
var midi_event = new MIDIEvent();
|
||||
midi_event.setup([midi_cmd, elem.data[0], elem.data[1]]);
|
||||
this.trigger("note", midi_event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
LGMIDIFromFile.prototype.play = function()
|
||||
{
|
||||
this._playing = true;
|
||||
this._current_time = 0;
|
||||
for(var i = 0; i < this._midi.tracks; ++i)
|
||||
{
|
||||
var track = this._midi.track[i];
|
||||
track._last_pos = 0;
|
||||
track._time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
LGMIDIFromFile.prototype.loadMIDIFile = function(url)
|
||||
{
|
||||
var that = this;
|
||||
LiteGraph.fetchFile( url, "arraybuffer", function(data)
|
||||
{
|
||||
that.boxcolor = "#AFA";
|
||||
that._midi = MidiParser.parse( new Uint8Array(data) );
|
||||
if(that.properties.autoplay)
|
||||
that.play();
|
||||
}, function(err){
|
||||
that.boxcolor = "#FAA";
|
||||
that._midi = null;
|
||||
});
|
||||
}
|
||||
|
||||
LGMIDIFromFile.prototype.onDropFile = function(file)
|
||||
{
|
||||
this.properties.url = "";
|
||||
this.loadMIDIFile( file );
|
||||
}
|
||||
|
||||
LiteGraph.registerNodeType("midi/fromFile", LGMIDIFromFile);
|
||||
|
||||
|
||||
function LGMIDIPlay() {
|
||||
this.properties = {
|
||||
volume: 0.5,
|
||||
|
||||
Reference in New Issue
Block a user