mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-27 09:45:13 +00:00
added more verbose error
This commit is contained in:
@@ -61,6 +61,15 @@ MIDIEvent.computePitch = function( note )
|
||||
return Math.pow(2, (note - 69) / 12 ) * 440;
|
||||
}
|
||||
|
||||
MIDIEvent.prototype.getCC = function()
|
||||
{
|
||||
return this.data[1];
|
||||
}
|
||||
|
||||
MIDIEvent.prototype.getCCValue = function()
|
||||
{
|
||||
return this.data[2];
|
||||
}
|
||||
|
||||
//not tested, there is a formula missing here
|
||||
MIDIEvent.prototype.getPitchBend = function()
|
||||
@@ -188,9 +197,18 @@ function MIDIInterface( on_ready, on_error )
|
||||
|
||||
this.on_ready = on_ready;
|
||||
|
||||
this.state = {
|
||||
note: [],
|
||||
cc: []
|
||||
};
|
||||
|
||||
|
||||
|
||||
navigator.requestMIDIAccess().then( this.onMIDISuccess.bind(this), this.onMIDIFailure.bind(this) );
|
||||
}
|
||||
|
||||
MIDIInterface.input = null;
|
||||
|
||||
MIDIInterface.MIDIEvent = MIDIEvent;
|
||||
|
||||
MIDIInterface.prototype.onMIDISuccess = function(midiAccess)
|
||||
@@ -209,8 +227,41 @@ MIDIInterface.prototype.updatePorts = function()
|
||||
var midi = this.midi;
|
||||
this.input_ports = midi.inputs;
|
||||
var num = 0;
|
||||
|
||||
var it = this.input_ports.values();
|
||||
var it_value = it.next();
|
||||
while( it_value && it_value.done === false )
|
||||
{
|
||||
var port_info = it_value.value;
|
||||
console.log( "Input port [type:'" + port_info.type + "'] id:'" + port_info.id +
|
||||
"' manufacturer:'" + port_info.manufacturer + "' name:'" + port_info.name +
|
||||
"' version:'" + port_info.version + "'" );
|
||||
num++;
|
||||
it_value = it.next();
|
||||
}
|
||||
this.num_input_ports = num;
|
||||
|
||||
num = 0;
|
||||
this.output_ports = midi.outputs;
|
||||
var it = this.output_ports.values();
|
||||
var it_value = it.next();
|
||||
while( it_value && it_value.done === false )
|
||||
{
|
||||
var port_info = it_value.value;
|
||||
console.log( "Output port [type:'" + port_info.type + "'] id:'" + port_info.id +
|
||||
"' manufacturer:'" + port_info.manufacturer + "' name:'" + port_info.name +
|
||||
"' version:'" + port_info.version + "'" );
|
||||
num++;
|
||||
it_value = it.next();
|
||||
}
|
||||
this.num_output_ports = num;
|
||||
|
||||
|
||||
/* OLD WAY
|
||||
for (var i = 0; i < this.input_ports.size; ++i) {
|
||||
var input = this.input_ports.get(i);
|
||||
if(!input)
|
||||
continue; //sometimes it is null?!
|
||||
console.log( "Input port [type:'" + input.type + "'] id:'" + input.id +
|
||||
"' manufacturer:'" + input.manufacturer + "' name:'" + input.name +
|
||||
"' version:'" + input.version + "'" );
|
||||
@@ -223,12 +274,15 @@ MIDIInterface.prototype.updatePorts = function()
|
||||
this.output_ports = midi.outputs;
|
||||
for (var i = 0; i < this.output_ports.size; ++i) {
|
||||
var output = this.output_ports.get(i);
|
||||
if(!output)
|
||||
continue;
|
||||
console.log( "Output port [type:'" + output.type + "'] id:'" + output.id +
|
||||
"' manufacturer:'" + output.manufacturer + "' name:'" + output.name +
|
||||
"' version:'" + output.version + "'" );
|
||||
num++;
|
||||
}
|
||||
this.num_output_ports = num;
|
||||
*/
|
||||
}
|
||||
|
||||
MIDIInterface.prototype.onMIDIFailure = function(msg)
|
||||
@@ -236,14 +290,17 @@ MIDIInterface.prototype.onMIDIFailure = function(msg)
|
||||
console.error( "Failed to get MIDI access - " + msg );
|
||||
}
|
||||
|
||||
MIDIInterface.prototype.openInputPort = function( port, callback)
|
||||
MIDIInterface.prototype.openInputPort = function( port, callback )
|
||||
{
|
||||
var input_port = this.input_ports.get( port );
|
||||
var input_port = this.input_ports.get( "input-" + port );
|
||||
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)
|
||||
@@ -258,15 +315,27 @@ MIDIInterface.parseMsg = function(data)
|
||||
|
||||
}
|
||||
|
||||
MIDIInterface.prototype.updateState = function( midi_event )
|
||||
{
|
||||
switch( midi_event.cmd )
|
||||
{
|
||||
case MIDIEvent.NOTEON: this.state.note[ midi_event.value1|0 ] = midi_event.value2; break;
|
||||
case MIDIEvent.NOTEOFF: this.state.note[ midi_event.value1|0 ] = 0; break;
|
||||
case MIDIEvent.CONTROLLERCHANGE: this.state.cc[ midi_event.getCC() ] = midi_event.getCCValue(); break;
|
||||
}
|
||||
}
|
||||
|
||||
MIDIInterface.prototype.sendMIDI = function( port, midi_data )
|
||||
{
|
||||
if( !midi_data )
|
||||
return;
|
||||
|
||||
var output_port = this.output_ports.get(port);
|
||||
var output_port = this.output_ports.get( "output-" + port );
|
||||
if(!output_port)
|
||||
return;
|
||||
|
||||
MIDIInterface.output = this;
|
||||
|
||||
if( midi_data.constructor === MIDIEvent)
|
||||
output_port.send( midi_data.data );
|
||||
else
|
||||
@@ -308,7 +377,7 @@ LGMIDIIn.prototype.getPropertyInfo = function(name)
|
||||
var values = {};
|
||||
for (var i = 0; i < this._midi.input_ports.size; ++i)
|
||||
{
|
||||
var input = this._midi.input_ports.get(i);
|
||||
var input = this._midi.input_ports.get( "input-" + i);
|
||||
values[i] = i + ".- " + input.name + " version:" + input.version;
|
||||
}
|
||||
return { type: "enum", values: values };
|
||||
@@ -351,6 +420,7 @@ LGMIDIIn.prototype.onExecute = function()
|
||||
var v = null;
|
||||
switch (output.name)
|
||||
{
|
||||
case "midi": v = this._midi; break;
|
||||
case "last_midi": v = last; break;
|
||||
default:
|
||||
continue;
|
||||
@@ -565,8 +635,10 @@ LGMIDIEvent.prototype.onExecute = function()
|
||||
v.channel = props.channel;
|
||||
break;
|
||||
case "command": v = props.cmd; break;
|
||||
case "note": v = (props.cmd == MIDIEvent.NOTEON || props.cmd == MIDIEvent.NOTEOFF) ? props.value1 : NULL; break;
|
||||
case "velocity": v = props.cmd == MIDIEvent.NOTEON ? props.value2 : NULL; break;
|
||||
case "cc": v = props.value1; break;
|
||||
case "cc_value": v = props.value2; break;
|
||||
case "note": v = (props.cmd == MIDIEvent.NOTEON || props.cmd == MIDIEvent.NOTEOFF) ? props.value1 : null; break;
|
||||
case "velocity": v = props.cmd == MIDIEvent.NOTEON ? props.value2 : null; break;
|
||||
case "pitch": v = props.cmd == MIDIEvent.NOTEON ? MIDIEvent.computePitch( props.value1 ) : null; break;
|
||||
case "pitchbend": v = props.cmd == MIDIEvent.PITCHBEND ? MIDIEvent.computePitchBend( props.value1, props.value2 ) : null; break;
|
||||
default:
|
||||
@@ -592,6 +664,8 @@ LGMIDIEvent.prototype.onGetOutputs = function() {
|
||||
["command","number"],
|
||||
["note","number"],
|
||||
["velocity","number"],
|
||||
["cc","number"],
|
||||
["cc_value","number"],
|
||||
["pitch","number"],
|
||||
["pitchbend","number"]
|
||||
];
|
||||
@@ -601,6 +675,31 @@ LGMIDIEvent.prototype.onGetOutputs = function() {
|
||||
LiteGraph.registerNodeType("midi/event", LGMIDIEvent);
|
||||
|
||||
|
||||
function LGMIDICC()
|
||||
{
|
||||
this.properties = {
|
||||
// channel: 0,
|
||||
cc: 1,
|
||||
value: 0
|
||||
};
|
||||
|
||||
this.addOutput( "value", "number" );
|
||||
}
|
||||
|
||||
LGMIDICC.title = "MIDICC";
|
||||
LGMIDICC.desc = "gets a Controller Change";
|
||||
|
||||
LGMIDICC.prototype.onExecute = function()
|
||||
{
|
||||
var props = this.properties;
|
||||
if( MIDIInterface.input )
|
||||
this.properties.value = MIDIInterface.input.state.cc[ this.properties.cc ];
|
||||
this.setOutputData( 0, this.properties.value );
|
||||
}
|
||||
|
||||
LiteGraph.registerNodeType("midi/cc", LGMIDICC);
|
||||
|
||||
|
||||
|
||||
|
||||
function now() { return window.performance.now() }
|
||||
|
||||
Reference in New Issue
Block a user