Thanks @Daniel !
I've begun to try and do just what you've described but haven't had any luck. I have the libraries referenced in the head.
I mostly want to have an element when clicked play a sound from an oscillator like this example
I tried copying in just this part of the code into a javascript function in HYPE:
var notes = [ 60, 62, 64, 65, 67, 69, 71];
// For automatically playing the song
var index = 0;
var song = [
{ note: 4, duration: 400, display: "D" },
{ note: 0, duration: 200, display: "G" },
{ note: 1, duration: 200, display: "A" },
{ note: 2, duration: 200, display: "B" },
{ note: 3, duration: 200, display: "C" },
{ note: 4, duration: 400, display: "D" },
{ note: 0, duration: 400, display: "G" },
{ note: 0, duration: 400, display: "G" }
];
var trigger = 0;
var autoplay = false;
var osc;
// A triangle oscillator
osc = new p5.TriOsc();
// Start silent
osc.start();
osc.amp(0);
function playNote(note, duration) {
osc.freq(midiToFreq(note));
// Fade it in
osc.fade(0.5,0.2);
// If we sest a duration, fade it out
if (duration) {
setTimeout(function() {
osc.fade(0,0.2);
}, duration-50);
}
// When we click
function mousePressed() {
// Map mouse to the key index
var key = floor(map(mouseX, 0, width, 0, notes.length));
playNote(notes[key]);
}
// Fade it out when we release
function mouseReleased() {
osc.fade(0,0.5);
}