generativefm / generators

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

makePiece never completing #4

Closed johncpalmer closed 3 years ago

johncpalmer commented 4 years ago

I'm attempting to import a piece using the same code in the README. However, it appears the makePiece is never completing and reaching the promise. I've messed around with a few permutations of the code but can't seem to crack it, even if waiting for the user to click a button to call the function. Here is what I've got now. Any idea how I could make this play?

By the way, thanks for making such awesome stuff. I use generative.fm all the time.

export const playMusic = () => {
  console.log("Calling playMusic"); // this prints
  makePiece({
    audioContext: Tone.context,
    destination: Tone.Master,
    samples: wav
  }).then(cleanUp => {
    console.log("Ready to start") // this never prints
    // Starting the piece
    // Make sure you follow the Chrome Autoplay policy: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio
    Tone.Transport.start();
  });
};
czfandyslash commented 4 years ago

I'm attempting to import a piece using the same code in the README. However, it appears the makePiece is never completing and reaching the promise. I've messed around with a few permutations of the code but can't seem to crack it, even if waiting for the user to click a button to call the function. Here is what I've got now. Any idea how I could make this play?

By the way, thanks for making such awesome stuff. I use generative.fm all the time.

export const playMusic = () => {
  console.log("Calling playMusic"); // this prints
  makePiece({
    audioContext: Tone.context,
    destination: Tone.Master,
    samples: wav
  }).then(cleanUp => {
    console.log("Ready to start") // this never prints
    // Starting the piece
    // Make sure you follow the Chrome Autoplay policy: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio
    Tone.Transport.start();
  });
};

Is there any updated solutions? The same problem makes me confused as well, and i guess the cleanUp function which is the return of makePiece may causes the error.

alexbainter commented 3 years ago

Hey sorry, this totally slipped under my radar.

There are a couple extra steps you need to get the pieces working locally, though I'm surprised you didn't get any more helpful output when you tried these out. First you'll need to build and host the samples files as per https://github.com/generative-music/samples-alex-bainter#local-development.

Once those are ready, you need to pass "http://localhost:6969" as the host parameter when you get the sample index.

(The reason they don't just download from my CDN is that I have to pay for that bandwidth)

I think your original issue was just that the sample files were 404ing. However, I've since changed the API drastically and haven't had time to update the documentation. Here are updated instructions for getting these to run locally:

  1. Clone https://github.com/generative-music/samples-alex-bainter to your machine.
  2. Follow the instructions for building the sample files locally.
  3. Follow the instructions for serving the sample files locally (requires Docker and docker-compose).
import getSamples from '@generative-music/samples-alex-bainter'; // you may need to `npm link` this from your local directory.
import createWebProvider from '@generative-music/web-provider';
import createWebLibrary from '@generative-music/web-library';
import * as Tone from 'tone'; // Tone v14
import activate from '@generative-music/piece-eno-machine';

const sampleIndex = getSamples({ format: 'wav', host: 'http://localhost:6969' });
const provider = createWebProvider();
const sampleLibrary = createWebLibrary({ sampleIndex, provider });

export const playMusic = () => {
  console.log("Calling playMusic");
  activate({
    sampleLibrary,
    context: Tone.context,
    destination: Tone.Destination,
  }).then(([deactivate, schedule]) => {
    schedule();
    console.log("Ready to start");
    // Starting the piece
    Tone.Transport.start();
  });
};

When I have more time I intend to write tons of documentation for these libraries. Let me know if you have any other questions or run into any other issues (to be honest, if the sample build script succeeds without issues I'll be surprised).

alexbainter commented 3 years ago

Closing this as there's now updated documentation