Today’s Exercise:

Tone.JS Sampler Object - Playing Notes with Samples

Tone.Sampler documentation on Tone.JS web site.

let sampler;
let baseURL= "<https://publicbucket2share.s3.amazonaws.com/Dirt-Samples/>";

function setup() {
  createCanvas(400, 400);
  
  btn=createButton("Play Note 1");
  btn.position(100,200);
  btn.mousePressed(playNote1);

  btn=createButton("Play Note 2");
  btn.position(200,200);
  btn.mousePressed(playNote2);
  
  
  sampler = new Tone.Sampler({
	urls: {
		A2: "juno/03_juno_chorus_low.wav",
		A3: "juno/04_juno_chorus_mid.wav",
	},
	baseUrl: baseURL,
  }).toDestination();
}

function playNote1() {
  sampler.triggerAttackRelease(["C2","E2","G2"],0.5);
}

function playNote2() {
  sampler.triggerAttackRelease(["A3","C3","E3"]);
}

function draw() {
  background(220);
}

An example that we reviewed in class at the P5 Editor