xxxxxxxxxx
101
let output;
let midiIn;
let note;
let notename;
let channel = 1;
let bg;
let s = 0;
WebMidi.enable(function(err) {
if (err) {
console.log("WebMidi not be enabled.", err);
} else {
console.log("WebMidi enabled!");
}
console.log(WebMidi.inputs);
console.log(WebMidi.outputs);
//midiIn = WebMidi.getInputByName("LPK25");
midiIn = WebMidi.getInputByName("IAC Driver Bus 1");
///output = WebMidi.getOutputByName("Arduino NANO 33 IoT");
output = WebMidi.getOutputByName("IAC Driver Bus 1");
//console.log(output);
midiIn.addListener('noteon', 1, function(inNote) {
let note = inNote.note.rawValue
output.playNote("E2");
console.log(inNote)
if(note > 5){
bg = color(255,0,0);
console.log("OUT")
}
if(note == "E"){
bg = color(0,255,0);
}
if(note == "G"){
bg = color(255,0,255);
}
bg = color(random(255), random(255), random(255))
// console.log(note);
});
midiIn.addListener('noteoff', 'all', resetBg);
midiIn.addListener('noteon', '15', drumViz);
midiIn.addListener('noteon', '14', bgViz);
});
function drumViz(drumIn){
s = drumIn.rawVelocity *2
// console.log(s);
}
function bgViz(inNote){
// s = drumIn.rawVelocity *2
//console.log(s);
let note = inNote.note.name;
bg = color(random(255), random(255), random(255))
}
function resetBg(receivedMidi) {
// console.log(receivedMidi);
bg = color(0, 0, 0);
}
function setup() {
createCanvas(400, 400);
bg = color(255, 255, 255)
}
function draw() {
background(bg);
stroke(0);
fill(255);
ellipse(width/2,height/2, s, s);
s-=10;
if(s<=0){
s=0
}
}
function mousePressed(){
output.playNote("e1");
}