generativefm / generators

A collection of generative music pieces for generative.fm
MIT License
560 stars 59 forks source link

Passing effects to playing pieces #7

Closed sepowitz closed 2 years ago

sepowitz commented 3 years ago

Hey Alex,

Firstly, I just wanted to say how great this (these repos) are. I was able to get samples set up locally, and have been playing around the some of the existing pieces you've created.

I was wondering if there is an existing pattern for manipulating pieces using Tone.js as they are playing via the activate method you provide.

For example, I begin playing a piece, and then can apply effects to it via some user input.

Thanks again!

alexbainter commented 3 years ago

You can manipulate the audio pretty easily by passing a ToneAudioNode as the destination prop to activate and then manipulating that node however you like.

For example:

import activate from '@generative-music/piece-zed';
import { Chorus } from 'tone';

const chorusNode = new Chorus().toDestination(); // create a chorus effect node and connect it to the audio destination
activate({
  destination: chorusNode, // route the output of this generator through the chorus node
  //...
}).then(([deactivate, schedule]) => {
  const end = schedule();

  // later, in response to some user input
  chorusNode.frequency.value = 1;
  chorusNode.wet.value = 0.5;
  // etc
});

You could even build a whole chain of audio nodes, and just pass the first node of your chain as the destination prop.