How can I make Tone.js an processing.js communicate?

edited July 2017 in JavaScript Mode

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

Tagged:

Answers

Sign In or Register to comment.