xxxxxxxxxx
80
// Copyright (c) 2019 ml5
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
/* ===
IMALR using ml5 Example
PoseNet example using p5.js
Aug 05 David Rios
=== */
let input;
let output;
let note;
let channel = 1;
let playing = false;
let checkbox;
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);
output = WebMidi.getOutputByName("IAC Driver Bus 1");
input = WebMidi.getInputByName("IAC Driver Bus 1");
console.log(input);
});
function setup() {
createCanvas(windowWidth, windowHeight);
checkbox = createCheckbox("play!");
checkbox.position(20,60);
checkbox.changed( playClip );
textSize(36);
}
function draw() {
background(220);
text("playing a MIDI note of: "+ note , 20,40);
}
function mousePressed(){
note = int(map(mouseX, 0,width , 20, 96));
if( !playing ){ // playing == false
output.playNote(note , 1, 127);
playing = true;
}
if(playing){
output.stopNote(note , 1, 127);
playing = false;
}
}
function playClip(){
if( checkbox.checked()){
output.sendControlChange(16 , 127 , 2);
}else{
output.sendControlChange(17 , 127 , 2);
}
}