We are about to switch to a new forum software. Until then we have removed the registration on this forum.
First of all I want to excuse if this post is not in the correct category of the forum, or if this text formatting is not at all correct, once more.
I am trying to do a simple experiment. I have a processing code, that draws something while the mouse is pressed:
void draw() {
if (mousePressed == true){
point(mouseX, mouseY);
}
}
Then, I may embed this into an html file, using processing.js:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf‐8">
<title> Hello </title>
<script type="text/javascript" src="js/Tone.js" ></script>
<script src="/js/processing.js"></script>
<script>
//create a synth and connect it to the master output (your speakers)
var synth = new Tone.Synth().toMaster()
//play a middle 'C' for the duration of an 8th note
synth.triggerAttackRelease('C4', '8n')
</script>
</head>
<body>
<canvas data-processing-sources="/processing/processing.pde"></canvas>
</body>
I would like to trigger a Tone.js sound whenever I press the mouse in the processing canvas. For this, I imagine i should add an event listener in Tone.js side (this is the way to do it, it is in the tone.js github) and some line of code in the processing file.** I don't now what I have to add!** I looked in the reference guide an see the are things like selectInput(), but I am not sure if this is what I am looking for at all. And If I a should add some library, in the processing file I am also not sure which one it should be.
Thanks in advance
Answers
Library "processing.js" (a.k.a Pjs or JavaScript Mode) is mainly focused on transpiling sketches written in Java Mode to JS syntax, so they can run on the web too. ~O)
However, when we use 3rd-party libraries, Pjs can't make that conversion anymore! :-O
It's also possible to write sketches in Pjs using JS syntax in place of Java's: :ar!
http://ProcessingJS.org/articles/jsQuickStart.html#javascriptonlyprocessingcode
But then, we've already got the not-so-new p5.js flavor for it: :-\"